Consulting

Results 1 to 4 of 4

Thread: Determining number of rolls to delete

  1. #1
    VBAX Regular
    Joined
    Jul 2016
    Posts
    17
    Location

    Question Determining number of rolls to delete

    Hi,

    I am writing a program to check if the current row is the last row in the set of data.
    Expected result should be if its not the last row, then select current row and all rows below and delete, and if it is the last row, then delete only this row. But it doesn't seem to be working this way, if its the last row, then all rows below are deleted (I have some populated cells apart from the main data set and those are deleted as well). Appreciate your advice!

    ActiveCell.Offset(1, 0).Select
    If Not IsEmpty(ActiveCell.Value) Then
    ActiveCell.Offset(-1, 0).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.EntireRow.Delete
    Else
        ActiveCell.Offset(-1, 0).Select
        ActiveCell.EntireRow.Delete
        
    End If

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Selecting instead of deleting (change .Select to .Delete or .Clear or .ClearContents):
    Sub blah()
    If Not IsEmpty(ActiveCell.Value) Then  'if the active cell is empty, abort (saves deleting one row if the active cell is blank).
      Do Until IsEmpty(ActiveCell.Offset(os + 1).Value)
        os = os + 1
      Loop
      Range(ActiveCell, ActiveCell.Offset(os)).EntireRow.Select
    End If
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Jul 2016
    Posts
    17
    Location
    Thanks for your help! But I have another problem here
    Not sure could it be because the rows that I am deleting is from filtered data, so it seems to be affecting other parts of my program

  4. #4
    VBAX Regular
    Joined
    Jul 2016
    Posts
    17
    Location
    Sorry my bad!! Its a bug in another part of my program! Your code works perfectly fine! Thanks so much for your help!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •