Make the change I show in red above.Hi, this is such a wonderful thread, whereby I have already used something from it, but could do with some help with the below.
As shown in page 1 of this thread, I wanted to remove all rows that contained any data in cells in column T, so only leaving blanks - BUT I wanted it to start from row 7 as I have blank rows above this that need to be kept.
I tried the below...but it deletes my title rows. It must be simple, but how do I get this to start from row 7?
Last = Cells(Rows.Count, "T").End(xlUp).Row
For i = Last To 7 Step -1
If (Cells(i, "T").Value) <> "" Then
Cells(i, "A").EntireRow.Delete
End If
Next i
End Sub
Try it this way...Hi,
I have another question regarding the above formula...
Last = Cells(Rows.Count, "T").End(xlUp).Row
For i = Last To 7 Step -1
If Cells(i, "F").Value = Cells(I, "G").Value Then
Cells(i, "A").EntireRow.Delete
End If
Next I
How do I get it to delete any rows where the content of column F is equal to the content of column G? So, I only want the rows left where the content differs in columns F and G - again, only starting from row 7.
Last = Cells(Rows.Count, "T").End(xlUp).Row
For i = Last To 7 Step -1
If Cells(i, "F").Value = Cells(i, "G").Value Then
Rows(i).Delete
End If
Next i
VBA code is completely different than worksheet formulas, so rarely, if ever, would you be able to take a worksheet formula's construction an be able to use it in a VBA coded procedure.I tried adding an =IF($L7=$M7 formula, in many variants, but none did what I wanted.
Sub Test()
Application.ScreenUpdating = False
Dim i As Integer
Dim b As Integer
Dim Last As Long
For b = 1 To 2
With Sheets(b)
Last = .Cells(Rows.Count, "J").End(xlUp).Row
For i = Last To 5 Step -1
If .Cells(i, "J").Value <= 0 Or .Cells(i, "J").Value > 2000 Then
.Rows(i).Delete
End If
Next i
End With
Next
Application.ScreenUpdating = True
End Sub
Here is another macro for you to try (it should be faster than the method you are attempting to use), just replace the two red example sheet names with your actual sheet names...I have another question similar to the above ones.
Starting from row 5, I only want column J to show data between 1 and 2000 inclusive, deleting all other rows of data.
I need it to run on 2 identical tabs, yet when running the macro, it failed on one of them, highlighting the "If (Cells(i, "J").Value) <= 0 Then" row of text.
Sub Keep1to2000()
Dim Addr As String, WS As Worksheet
For Each WS In Sheets(Array("[B][COLOR="#FF0000"]Sheet1[/COLOR][/B]", "[B][COLOR="#FF0000"]Sheet2[/COLOR][/B]"))
Addr = "'" & WS.Name & "'!J5:J" & WS.Cells(Rows.Count, "J").End(xlUp).Row
WS.Range(Addr) = Evaluate(Replace("IF((@<1)+(@>2000),""#N/A"",IF(@="""","""",@))", "@", Addr))
On Error Resume Next
WS.Columns("J").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
Next
End Sub