Deleting Rows based on Value of Column

UofA_Hogs

New Member
Joined
Aug 22, 2011
Messages
4
Hello there,

This is my first post. I am pretty decent at excel but just beginning in writing VB Macros

I am trying to figure out how to write a script to delete entire rows based on a certain value in a column.


Any Help?

Thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I am not sure why this is not working, I keep getting an error message for the following code:


Sub Delete_row_loop()
Dim Firstrow As Integer
Dim Lastrow As Integer
Dim Lrow As Integer

Sheets("Script").Select
Firstrow = 2
Lastrow = .Cells(.Rows.Count, "A").End(x1up).Row



For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "D")
If Not IsError(.Value) Then
If .Value = "0" Then .EntireRow.Delete
End If
End With
Next Lrow
End Sub


The error message I keep getting is a Compile error: Invalid or unqualified reference.

Any information would be great.
 
Upvote 0
On your line:

Lastrow = .Cells(.Rows.Count, "A").End(x1up).Row

remove both "."'s before the Cells( and Rows
 
Upvote 0
I think the problems are in

You must reference a sheet (not select) like

With Sheets("Script")
....
....
End with

End Sub


and in

End(x1Up)

try
End(xlUp)

xl not x1

HTH

M.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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