Hi, I just wanted to ask how can I retain the rows if column F or StartString(Font in red) starts with number. Below is my code.
Rich (BB code):
Sub DeleteRowsraw()
Dim c As Range, DeleteRange As Range, DataRange As Range
Dim LR As Long
Dim i As Long
Dim StartString As String
'change sheet name as required
With Worksheets("Sheet1")
'find last row in range
LR = .Cells(.Rows.Count, "F").End(xlUp).Row
'range you are searching
Set DataRange = .Range("F1:F" & LR)
End With
StartString = "number only"
DataRange.EntireRow.Hidden = False
For Each c In DataRange.Cells
If Left(c.Value, 1) <> StartString Then
If DeleteRange Is Nothing Then
Set DeleteRange = c
Else
Set DeleteRange = Union(DeleteRange, c)
End If
End If
Next c
'delete all matched rows in one go
If Not DeleteRange Is Nothing Then DeleteRange.EntireRow.Delete
End Sub
Attachments
Last edited by a moderator: