Creating a macro

J

JC

Hey guys,
I need to create a macro and i've never done this...i think that this is a
simple macro to build, just need a little help...

I need to build a macro that will delete an entire row when a particular
column =zero....Example...

If cell AD5, AD43 and AD 50 equal zero, i want the macro to delete row 5, 43
and 50.

Thanks!!
 
J

JLGWhiz

Press Alt + F11 to open the VB editor, If the window is dark, use
Insert>Module and then paste the code below into the window. You can run the
code from Excel by clicking Tools>Macro>Macros>Run. Make sure this macro is
in the top window of the dialogue box.

Sub delRws()
If Range("AD5") = 0 And Range("AD43") = 0 _
And Range("AD50") = 0 Then
Set delRng = Application.Union(Rows(5), Rows(43), Rows(50))
delRng.EntireRow.Delete
End If
End Sub
 
J

JC

JLGWhiz,
Can we make this say that anywhere in Column AD there is a zero, delete that
corresponding row??
 
M

Mike H

Maybe this

Sub delete_Me()
lastrow = Range("AD65536").End(xlUp).Row
For x = lastrow To 1 Step -1
If Cells(x, 30).Value <> "" Then
If Cells(x, 30).Value = 0 Then
Rows(x).Delete
End If
End If
Next
End Sub


Mike
 
J

JC

Thank-You!!!!

Mike H said:
Maybe this

Sub delete_Me()
lastrow = Range("AD65536").End(xlUp).Row
For x = lastrow To 1 Step -1
If Cells(x, 30).Value <> "" Then
If Cells(x, 30).Value = 0 Then
Rows(x).Delete
End If
End If
Next
End Sub


Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top