Hello everyone,
I would appreciate some help with making the following code more efficient (got it online). It works as it is but I have two issues with it that I can't seem to solve:
1) I can't seem to be able to replace this code
.Value = "2014-09-05_2014-10-03"
with something more flexible like the following. Am I doing something wrong or is it the way the macro is made that prevents this change?
2) I read that structuring a range reference in the following way was "frowned upon." Why is that and how do I improve this?
Range("M" & Lrow & ":" & "P" & Lrow)
If there is anything else you see that can improve the code, please let me know. The entire code is below.
Sub Loop_Example()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
With Worksheets("ref")
'Set the first and last row to loop through
Firstrow = 2
Lastrow = .Cells(.Rows.Count, "P").End(xlUp).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the P column in this example
With .Cells(Lrow, "P")
If Not IsError(.Value) Then
If .Value = "2014-09-05_2014-10-03" Then Range("M" & Lrow & ":" & "P" & Lrow).Delete (xlShiftUp)
'This will delete cells in the M:P column range where at lrow, .Value is the same as above
'in Column P, case sensitive.
End If
End With
Next Lrow
End With
End Sub
Thanks!
Geoff.
Bookmarks