Results 1 to 3 of 3

Thread: vba delete rows

  1. #1
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Dim ws As Worksheet
    Dim RowFin As Long
    Dim Rng As Range
    Dim Find As Range
    
    	Set ws = Worksheets("Sheet1")
    	
    'Set start and end rows
    
    	RowFin = ws.Cells(ws.Rows.count, 9).End(xlUp).Row - 1
    	
    Set Rng = ws.Range("I18:J" & RowFin)
    For Each Find In Rng
    	If Find = 0 Then
    		Rng.EntireRow.Delete
    	End If
    Next
    I need to delete the row if both I and J = 0. Can anyone see the problem with my logic?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You need to loop backwards.

    Code:
    Dim r As Long
    For r = RowFin To 18 Step -1
      If ws.Range("I" & r) = 0 And ws.Range("J" & r) = 0 Then
    	ws.Range("I" & r).EntireRow.Delete
      End If
    Next r

  3. #3

Posting Permissions

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