Delete Row if Cell value Starts with...

programsam

Board Regular
Joined
Feb 10, 2016
Messages
123
Gang, LR returns 0 Value... sure it's an easy fix. What am I doing wrong?

Code:
Sub freshList2()With Sheets("sL")


Dim LR As Long


LR = Range("A" & .Rows.Count).End(xlUp).Row


    For i = 1 To LR Step -1
        If Left(Range("A" & i).Value, 1) <> "1*" Then
            .Rows(i).EntireRow.Delete
        End If
    Next i




End With






End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try using
Code:
LR = cells(rows.count,"A").end(xlup).row
 
Last edited:
Upvote 0
The below works for me...

Code:
Sub freshList2()
    With Sheets("sL")

        Dim LR As Long, i As Long
        LR = .Range("A" & .Rows.Count).End(xlUp).Row


        For i = LR To 2 Step -1
            If Left(.Range("A" & i).Value, 1) <> 1 Then
                .Rows(i).Delete
            End If
        Next i

    End With

End Sub
 
Last edited:
Upvote 0
Gang, LR returns 0 Value... sure it's an easy fix. What am I doing wrong?

Code:
LR = Range("A" & .Rows.Count).End(xlUp).Row
Remove the dot in front of the Rows keyword (you do not have With statement for that dot to refer back to).
 
Upvote 0
Remove the dot in front of the Rows keyword (you do not have With statement for that dot to refer back to).

The OP has a With statement, it is just the board is displaying it bad and is on the Sub line.
 
Upvote 0
I think the OP had it wrong in their statement
LR returns 0 Value
I think it is the i that was returning 0 because they had the LR and the i the wrong way around in
Code:
For i = 1 To LR Step -1
so it was doing a -1 step from 1 to 0.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top