Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Hiding rows if...


I am fairly new to using VBA, but it seems like I should be able to get
this to work. Unfortunatly I cannot. Here's the problem:

Let's say I have a range (B1:B10). Some of the values = 0. Others are
greater than zero. What I want my macro to do is hide the row if cell's
value is zero. So if B1 = 0 then hide row 1.

Obviously I could write an if then for each row, but my actualy project
has hundreds of rows. Besides, I want a cleaner code. I thought I
could do it...maybe someone could steer me in the right direction.

Thanks


--
jacksonz
------------------------------------------------------------------------
jacksonz's Profile: http://www.excelforum.com/member.php...o&userid=13728
View this thread: http://www.excelforum.com/showthread...hreadid=387198

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Hiding rows if...

This worked for me in Excel 2000

It also insures that non-zero rows are visible.

==============================
Dim lrw As Long, cel As Range, rng As Range

' find last row in Column B
lrw = Cells(Rows.Count, "B").End(xlUp).Row

' define range to search
Set rng = Range(Cells(1, 2), Cells(lrw, 2))

' loop through range
For Each cel In rng
If cel = 0 Then
Rows(cel.Row).EntireRow.Hidden = True
Else
Rows(cel.Row).AutoFit
End If
Next
=======================================

--
steveB

Remove "AYN" from email to respond
"jacksonz" wrote in
message ...

I am fairly new to using VBA, but it seems like I should be able to get
this to work. Unfortunatly I cannot. Here's the problem:

Let's say I have a range (B1:B10). Some of the values = 0. Others are
greater than zero. What I want my macro to do is hide the row if cell's
value is zero. So if B1 = 0 then hide row 1.

Obviously I could write an if then for each row, but my actualy project
has hundreds of rows. Besides, I want a cleaner code. I thought I
could do it...maybe someone could steer me in the right direction.

Thanks


--
jacksonz
------------------------------------------------------------------------
jacksonz's Profile:
http://www.excelforum.com/member.php...o&userid=13728
View this thread: http://www.excelforum.com/showthread...hreadid=387198



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Hiding rows if...


For Each cell In Range("B1:B10")
If cell.Value = 0 Then
cell.Entirerow.Hidden = True
End if
Next cell

--

HTH

RP
(remove nothere from the email address if mailing direct)


"jacksonz" wrote in
message ...

I am fairly new to using VBA, but it seems like I should be able to get
this to work. Unfortunatly I cannot. Here's the problem:

Let's say I have a range (B1:B10). Some of the values = 0. Others are
greater than zero. What I want my macro to do is hide the row if cell's
value is zero. So if B1 = 0 then hide row 1.

Obviously I could write an if then for each row, but my actualy project
has hundreds of rows. Besides, I want a cleaner code. I thought I
could do it...maybe someone could steer me in the right direction.

Thanks


--
jacksonz
------------------------------------------------------------------------
jacksonz's Profile:

http://www.excelforum.com/member.php...o&userid=13728
View this thread: http://www.excelforum.com/showthread...hreadid=387198



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
Color alternate rows when after hiding selected rows Monk[_2_] Excel Worksheet Functions 6 June 7th 08 01:36 AM
Hiding Specific Rows Based on Values in Other Rows Chris Excel Worksheet Functions 1 November 2nd 06 08:21 PM
Hiding a button when hiding rows fergusor Excel Discussion (Misc queries) 2 August 10th 06 02:31 PM
Hiding Rows if the linked rows are blank KG Excel Discussion (Misc queries) 9 May 18th 05 02:32 AM
Copying Rows when hiding other rows Neutron1871 Excel Worksheet Functions 2 November 3rd 04 11:38 PM


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

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"