Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default hiding rows using macro

Sub hideifzeros()
Dim a as Range
For Each a In Range(Cells(1,1),Cells(rows.count,1).End(xlup))
If a = 0 And a.Offset(0, 3) = 0 Then a.EntireRow.Hidden = True
Next
End Sub

column D is offset 3 from Column A.

--
Regards,
Tom Ogilvy


"Greg Stevens" wrote in message
...
Hello,

I am looking for some assistance here with a code I am trying to write for
an excel data. Here is the scenario:

I have 10 columns (A:J) with about 1000 rows. Each of those cells within
the 10 columns and 1000 rows contain numbers. We want to run a macro in
which for columns A and D, when and only if they both equal "0"then we

want
to hide that specific row and continue onto the next row and keep on

hiding
if the columns A and D both equal "zero" until the entire sheet has been
searched.

So far here is what I have but the macro is just taking the first row and
hiding regardless of values and stopping the

Sub hideifzeros()
For Each a In Selection
If a = 0 And a.Offset(0, 4) = 0 Then a.EntireRow.Hidden = True
Next
End Sub


Please assist, I would be very grateful as I am at a loss right now.


--
Greg



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default hiding rows using macro

Sub hideifzeros()
Dim a as Range
For Each a In Range(Cells(1,1),Cells(rows.count,1).End(xlup))
If a = 0 And a.Offset(0, 3) = 0 and _
not isempty(a) and Not isempty(a.offset(0,3)) _
Then a.EntireRow.Hidden = True
Next
End Sub

would be a start. I can only imagine that these two other type rows are
blank in columns A and D.

to demo from the immediate window
ActiveCell.ClearContents
? activeCell = 0
True

when you compare an empty activecell to 0 it is coerced to zero so the
comparison is number to number - thus it passes the test. The additions
explicitly check if the cells are empty.

--
Regards,
Tom Ogilvy


"Greg Stevens" wrote in message
...
Tom,

You are a savior, this works great but I have a few more questions and I
would appreciate your comment.

Between the rows filled with data (numbers) we have rows that are empty

for
spacing purpose (filler) and rows with wording (text). The macro is

running
correctly but it is collapsing the filler and text rows, in which we would
like these rows to remain unhidden.

Is there an addition code that we can put in?

Thanks in advance.

Regards,

Greg


"Tom Ogilvy" wrote:

Sub hideifzeros()
Dim a as Range
For Each a In Range(Cells(1,1),Cells(rows.count,1).End(xlup))
If a = 0 And a.Offset(0, 3) = 0 Then a.EntireRow.Hidden = True
Next
End Sub

column D is offset 3 from Column A.

--
Regards,
Tom Ogilvy


"Greg Stevens" wrote in message
...
Hello,

I am looking for some assistance here with a code I am trying to write

for
an excel data. Here is the scenario:

I have 10 columns (A:J) with about 1000 rows. Each of those cells

within
the 10 columns and 1000 rows contain numbers. We want to run a macro

in
which for columns A and D, when and only if they both equal "0"then

we
want
to hide that specific row and continue onto the next row and keep on

hiding
if the columns A and D both equal "zero" until the entire sheet has

been
searched.

So far here is what I have but the macro is just taking the first row

and
hiding regardless of values and stopping the

Sub hideifzeros()
For Each a In Selection
If a = 0 And a.Offset(0, 4) = 0 Then a.EntireRow.Hidden = True
Next
End Sub


Please assist, I would be very grateful as I am at a loss right now.


--
Greg






Reply
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
macro for hiding rows Khardy3352 New Users to Excel 4 February 11th 09 07:41 PM
How to code Macro for hiding rows Catherine Bond Excel Worksheet Functions 4 June 24th 06 10:13 AM
Hiding Rows in a VBA macro sarcher Excel Discussion (Misc queries) 1 May 15th 06 03:39 PM
Macro for hiding rows Linda Excel Discussion (Misc queries) 2 February 1st 06 09:26 PM
Macro for hiding rows Luke Excel Discussion (Misc queries) 22 December 24th 05 03:40 PM


All times are GMT +1. The time now is 03:46 PM.

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

About Us

"It's about Microsoft Excel"