PDA

View Full Version : [SOLVED:] Deletes a row if it does start with a number+ Loop



parscon
10-29-2013, 03:30 AM
I have a VBA code that will Deletes a row if it does start with a number but it will only delete 2 row like

A1: Apple
A2: 1 Apple
A3: 2 Apple
A4: 3 Apple
A5: 4 Apple


And result will be

A1: Apple
A2: 2 Apple
A3: 4 Apple

I need delete all of row that start with a number.
Thank you.



Sub DeleteRowifnumeric()
'Deletes a row if it does start with a number

Dim rng As Range
Dim cell As Range

Set rng = ActiveSheet.Range("A1").Resize(ActiveSheet.UsedRange.Count, 1)

For Each cell In rng
If IsNumeric(Left(cell.Value, 1)) = True Then cell.Rows.Delete Shift:=xlUp
Next cell

End Sub

mancubus
10-29-2013, 03:51 AM
try this.



Sub DeleteRowIfCellValueStartsWithANumber()
'Deletes a row if it does start with a number

Dim i As Long

For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
If IsNumeric(Left(Range("A" & i), 1)) Then Rows(i).Delete
Next i

End Sub

parscon
10-29-2013, 04:10 AM
Thank you Very Much .

mancubus
10-29-2013, 04:23 AM
you are welcome.