LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default vba code doesn't work

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

--
Regards,
Tom Ogilvy



"lschuh" wrote in message
...
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?

"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy



"lschuh" wrote in message
...
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.

"Tom Ogilvy" wrote:

Sub deletezero()
Dim i as Long
For i = ActiveCell.End(xlDown).Row To 1 Step -1
If Cells(i, 1) = 0 Then Rows(i).Delete
Next
End Sub

--
Regards,
Tom Ogilvy

"lschuh" wrote in message
...
I put your code into my macro and placed it in the personal.xls
It wouldn't run without declaring the variable i
I deleted the option explicit and it runs.
My question do you know how to declare the variable?
Should I delete the macro from the personal.xls and put it into

the
worksheet I am opening.
Will the macro run with other open worksheets. It seems to be

running
on
its own.
What is the best way to go?


"Don Guillett" wrote:

you might like this better
Sub deletezero()
For i = ActiveCell.End(xlDown).Row To 1 Step -1
If Cells(i, 1) = 0 Then Rows(i).Delete
Next
End Sub

--
Don Guillett
SalesAid Software

"lschuh" wrote in message
...
I found an example of vba code in a book "Using Excel 2003".

It
doesn't
work
and locks the entire application up. The code is:
Sub removenull()
Application.ScreenUpdating = False
Do Until ActiveCell.Value = " "
If ActiveCell.Value = 0 Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub


It is supposed to remove 0 from rows and delete rows.

What is wrong with it?











 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I get this code to work? Sam Excel Programming 1 February 2nd 05 12:24 AM
Code Does Not Work Minitman[_4_] Excel Programming 21 December 16th 04 09:30 PM
Code Still Does Not Work Minitman[_4_] Excel Programming 8 December 14th 04 02:49 PM
Why my code do not work : - ( keepitcool Excel Programming 5 September 5th 03 06:28 PM
Why my code do not work : - ( Tom Ogilvy Excel Programming 1 August 31st 03 04:53 PM


All times are GMT +1. The time now is 07:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"