vba code doesn't work

G

Guest

I put that in and my worksheet just started blinking and I had to break out
of the application. It ran before when I removed the option explicit and
placed it in the personal.xls I put it in the worksheet I wanted it to
run in and it spun out.
 
T

Tom Ogilvy

First, it should go in a general module. If it ran without any action on
your part, then you must have placed it inside an event procedure or called
it from an event procedure.

the only macros that run without be told to run are macros fired by events.

If you want it to work in a specific column, then you might alter it to
refer to that column

Sub deletezero()
Dim i as Long
For i = Worksheets("sheet1").Range("B1") _
.End(xlDown).Row To 1 Step -1
If Worksheets("Sheet1").Cells(i, 1) = 0 Then _
Worksheets("Sheet1").Rows(i).Delete
Next
End Sub

As an example.

If you want to fire it when the workbook is opened, then call it from the
workbook_Open event found in the Thisworkbook.module.
 
G

Guest

I am going to try that. I am not that familiar with excel coding sometimes I
am not that familiar with any vba (sort of kidding). I need to look at what
I am asking this program to do.
 
G

Guest

what if I want to work within a specific range. The range being a1:q32
would it then scan that work area and make the changes the code is telling
it to?
 
T

Tom Ogilvy

Sub deletezero()
Dim i as Long
Dim cell as Range, dim rng as Range, rng1 as Range
For each cell in Worksheets("sheet1").Range("A1:Q32")
if not isempty(cell) and cell.value = 0 then
if rng is nothing then
set rng1 = rng
else
set rng1 = union(rng,rng1)
end if
end if
Next
if not rng1 is nothing then
rng1.Entirerow.Delete
End if
End Sub

If only a specific column in that range

Sub deletezero()
Dim i as Long
Dim cell as Range, dim rng as Range, rng1 as Range
For each cell in Worksheets("sheet1").Range("C1:C32")
if not isempty(cell) and cell.Value = 0 then
if rng is nothing then
set rng1 = rng
else
set rng1 = union(rng,rng1)
end if
end if
Next
if not rng1 is nothing then
rng1.Entirerow.Delete
End if
End Sub
 

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

Similar Threads


Top