Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Hiding rows only when a condition has been met

I am trying to come up with something that will look at rows 3 through 2800
and hide any row where the value in column g (of the respective row) was zero.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Hiding rows only when a condition has been met

Give this code a try...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
LastRow = Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End Sub

Rick



"ordnance1" wrote in message
...
I am trying to come up with something that will look at rows 3 through 2800
and hide any row where the value in column g (of the respective row) was
zero.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Hiding rows only when a condition has been met

Nothing happens when I run this code.


"Rick Rothstein (MVP - VB)" wrote in
message ...
Give this code a try...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
LastRow = Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End Sub

Rick



"ordnance1" wrote in message
...
I am trying to come up with something that will look at rows 3 through
2800
and hide any row where the value in column g (of the respective row) was
zero.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Hiding rows only when a condition has been met

Where are you running it from? It was designed to be placed in the code
window for the worksheet you want it to apply to. So, if Sheet3 is the
worksheet you want to hide the rows in, right-click the name tab for that
worksheet, select View Code from the menu that pops up, and copy/paste the
code into the code window that appeared. Then, go to Sheet3 and press
Alt+F8, select HideRowIfZeroInG from the list and click the Run button. If
you would like to keep the code in some different location, then we will
have to incorporate a reference to the sheet name within the code itself.
The following modification to what I posted earlier will allow that...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
With Worksheets("Sheet3")
LastRow = .Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In .Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End With
End Sub

Note: Change the reference to Sheet3 (keep the quote marks) in the With
statement to the actual sheet name you want to hide the rows on.

Rick



"Patrick C. Simonds" wrote in message
...
Nothing happens when I run this code.


"Rick Rothstein (MVP - VB)" wrote in
message ...
Give this code a try...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
LastRow = Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End Sub

Rick



"ordnance1" wrote in message
...
I am trying to come up with something that will look at rows 3 through
2800
and hide any row where the value in column g (of the respective row) was
zero.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Hiding rows only when a condition has been met

Thank you very much. I totally over looked to reference to sheet3


"Rick Rothstein (MVP - VB)" wrote in
message ...
Where are you running it from? It was designed to be placed in the code
window for the worksheet you want it to apply to. So, if Sheet3 is the
worksheet you want to hide the rows in, right-click the name tab for that
worksheet, select View Code from the menu that pops up, and copy/paste the
code into the code window that appeared. Then, go to Sheet3 and press
Alt+F8, select HideRowIfZeroInG from the list and click the Run button. If
you would like to keep the code in some different location, then we will
have to incorporate a reference to the sheet name within the code itself.
The following modification to what I posted earlier will allow that...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
With Worksheets("Sheet3")
LastRow = .Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In .Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End With
End Sub

Note: Change the reference to Sheet3 (keep the quote marks) in the With
statement to the actual sheet name you want to hide the rows on.

Rick



"Patrick C. Simonds" wrote in message
...
Nothing happens when I run this code.


"Rick Rothstein (MVP - VB)" wrote
in message ...
Give this code a try...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
LastRow = Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End Sub

Rick



"ordnance1" wrote in message
...
I am trying to come up with something that will look at rows 3 through
2800
and hide any row where the value in column g (of the respective row)
was zero.






  #6   Report Post  
Posted to microsoft.public.excel.programming
BJ BJ is offline
external usenet poster
 
Posts: 51
Default Hiding rows only when a condition has been met

Hi Rick

I tried to use the code and couldn't get it to work ... until ...

I either removed the 'And' portion in the following line or changed the
'And' to 'Or':

If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True

Isn't the line as originally written attempting to hide the row if the value
= 0 AND if the value isn't blank? So no rows will ever be hidden?

Just curious and thanks for all your help Rick.

Brett


"Rick Rothstein (MVP - VB)" wrote:

Where are you running it from? It was designed to be placed in the code
window for the worksheet you want it to apply to. So, if Sheet3 is the
worksheet you want to hide the rows in, right-click the name tab for that
worksheet, select View Code from the menu that pops up, and copy/paste the
code into the code window that appeared. Then, go to Sheet3 and press
Alt+F8, select HideRowIfZeroInG from the list and click the Run button. If
you would like to keep the code in some different location, then we will
have to incorporate a reference to the sheet name within the code itself.
The following modification to what I posted earlier will allow that...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
With Worksheets("Sheet3")
LastRow = .Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In .Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End With
End Sub

Note: Change the reference to Sheet3 (keep the quote marks) in the With
statement to the actual sheet name you want to hide the rows on.

Rick



"Patrick C. Simonds" wrote in message
...
Nothing happens when I run this code.


"Rick Rothstein (MVP - VB)" wrote in
message ...
Give this code a try...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
LastRow = Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End Sub

Rick



"ordnance1" wrote in message
...
I am trying to come up with something that will look at rows 3 through
2800
and hide any row where the value in column g (of the respective row) was
zero.




  #7   Report Post  
Posted to microsoft.public.excel.programming
BJ BJ is offline
external usenet poster
 
Posts: 51
Default Hiding rows only when a condition has been met

Hi Rick

As a follow-up ... I'd like to be able to unhide these specific rows as
well. I used your original code to do this but it does it line by line - not
very fast. Is there a simpler [quicker] macro that can unhide a set range of
rows? In my case it's row 85-136.

Thanks for your help Rick.

B

"Rick Rothstein (MVP - VB)" wrote:

Where are you running it from? It was designed to be placed in the code
window for the worksheet you want it to apply to. So, if Sheet3 is the
worksheet you want to hide the rows in, right-click the name tab for that
worksheet, select View Code from the menu that pops up, and copy/paste the
code into the code window that appeared. Then, go to Sheet3 and press
Alt+F8, select HideRowIfZeroInG from the list and click the Run button. If
you would like to keep the code in some different location, then we will
have to incorporate a reference to the sheet name within the code itself.
The following modification to what I posted earlier will allow that...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
With Worksheets("Sheet3")
LastRow = .Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In .Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End With
End Sub

Note: Change the reference to Sheet3 (keep the quote marks) in the With
statement to the actual sheet name you want to hide the rows on.

Rick



"Patrick C. Simonds" wrote in message
...
Nothing happens when I run this code.


"Rick Rothstein (MVP - VB)" wrote in
message ...
Give this code a try...

Sub HideRowIfZeroInG()
Dim R As Range
Dim LastRow As Long
LastRow = Cells(Rows.Count, "G").End(xlUp).Row
If LastRow 2800 Then LastRow = 2800
For Each R In Range("G3:G" & CStr(LastRow))
If R.Value = 0 And R.Value < "" Then R.EntireRow.Hidden = True
Next
End Sub

Rick



"ordnance1" wrote in message
...
I am trying to come up with something that will look at rows 3 through
2800
and hide any row where the value in column g (of the respective row) was
zero.




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 on condition Catherine Bond Excel Worksheet Functions 3 June 23rd 06 06:19 PM
Hiding cells on condition Pennington Excel Worksheet Functions 19 April 21st 05 12:30 AM


All times are GMT +1. The time now is 09:16 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"