Questionboy
New Member
- Joined
- Feb 2, 2012
- Messages
- 9
I've searched and searched for an answer to this and can't find a solution. I have written a code that compares Cells on 1 row to the Cells on the row above, if they match they get deleted. I've then looped it to run through each row and then repeat the whole process 15 times. I have got it to work when i declare the last row but if i try and use a dynamic last row the code fails. can someone point out my error.
The code below is what i'm trying to get working and it fails. with a comment as to how i can get it to work.
obviously it will work with me work around but i cannot guarantee i'll never have more than 100 rows of data
thank you for the advice.
The code below is what i'm trying to get working and it fails. with a comment as to how i can get it to work.
Code:
Sub test()
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For NN = 1 To 15 Step 1
For N = LastRow To 2 Step -1 'If i change this row to For N = 100 to 2 Step -1 the code does what i want
If Cells(N, 5) = Cells(N - 1, 5) And Cells(N, 6) = Cells(N - 1, 6) Then
Range(Cells(N, 5), Cells(N, 6)).Delete Shift:=xlToLeft
End If
Next N
Next NN
End Sub
obviously it will work with me work around but i cannot guarantee i'll never have more than 100 rows of data
thank you for the advice.