Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Macro to hide rows based on criteria

I am in the process of doing end of year financial reporting analysis
and I want to be able to run a macro that hides empty rows based on a
specific criteria.

Column C lists the accounts codes, column G is the YTD Actuals and
column H is the YTD Budget.

What I want to do, is.....

If there is a value in a row in Column C and if the value of the cell
in both column G & H is 0 the hide the row.

If anyone can point me in the right direction to research this further
would be sincerely appreciated.

PS: I am using MS Excel 2003
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default Macro to hide rows based on criteria

try to select yr data and use the macro:

Sub hideeeee()
On Error Resume Next
For Each cell In Selection
If IsNumeric(cell) And cell.Offset(0, 4) = 0 And cell.Offset(0, 5) = 0
Then
cell.Rows.EntireRow.Hidden = True
End If
Next cell

End Sub

HIH
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro to hide rows based on criteria

Try this

Sub stantial()
Dim myrange, hiderange As Range
Lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
Set myrange = Range("C1:C" & Lastrow)
For Each c In myrange

If c.Value < "" And c.Offset(, 4) = 0 And c.Offset(, 5) = 0 _
And c.Offset(, 4) < "" And c.Offset(, 5) < "" Then
If hiderange Is Nothing Then
Set hiderange = c.EntireRow
Else
Set hiderange = Union(hiderange, c.EntireRow)
End If
End If
Next
If Not hiderange Is Nothing Then
hiderange.EntireRow.Hidden = True
End If
End Sub

Mike

"Santa-D" wrote:

I am in the process of doing end of year financial reporting analysis
and I want to be able to run a macro that hides empty rows based on a
specific criteria.

Column C lists the accounts codes, column G is the YTD Actuals and
column H is the YTD Budget.

What I want to do, is.....

If there is a value in a row in Column C and if the value of the cell
in both column G & H is 0 the hide the row.

If anyone can point me in the right direction to research this further
would be sincerely appreciated.

PS: I am using MS Excel 2003

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default Macro to hide rows based on criteria

Mike is right
an empty cell will been as '0', so I have to adjust my macro

Sub hideeeee()
On Error Resume Next
For Each cell In Selection
If IsNumeric(cell) And cell.Offset(0, 4) = 0 And cell.Offset(0, 5) = 0
_
And Len(cell.Offset(0, 4)) 0 And Len(cell.Offset(0, 5) 0 Then
cell.Rows.EntireRow.Hidden = True
End If
Next cell

End Sub

sorry
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Macro to hide rows based on criteria

Thanks Jarek & Mike,

I was on the verge of using the xlUp but I've got a series of blank
rows in between each of the categories.
I ended up using a modified version of the with selection...

"E" for expense & "R" for revenue. If the value was "" then it would
skip and if it was "H" for Heading then it would be fine.


Sub hideeeee()
On Error Resume Next
For Each cell In Selection
If cell.Offset(0, -2) = "R" Or cell.Offset(0, -2) = "E" Then
If cell.Offset(0, 4) = 0 And cell.Offset(0, 5) = 0 _
And Len(cell.Offset(0, 4)) 0 And Len(cell.Offset(0, 5)) 0
Then
cell.Rows.EntireRow.Hidden = True
End If
End If
Next cell


End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Macro to hide rows based on criteria

On Jul 1, 4:00*pm, Santa-D wrote:
Thanks Jarek & Mike,

I was on the verge of using the xlUp but I've got a series of blank
rows in between each of the categories.
I ended up using a modified version of the with selection...

"E" for expense & "R" for revenue. *If the value was "" then it would
skip and if it was "H" for Heading then it would be fine.

Sub hideeeee()
On Error Resume Next
For Each cell In Selection
If cell.Offset(0, -2) = "R" Or cell.Offset(0, -2) = "E" Then
* * If cell.Offset(0, 4) = 0 And cell.Offset(0, 5) = 0 _
* * * And Len(cell.Offset(0, 4)) 0 And Len(cell.Offset(0, 5)) 0
Then
cell.Rows.EntireRow.Hidden = True
End If
End If
Next cell

End Sub


The only downside is that it didn't keep the highlight second row
conditional formatting when hiding all those rows....... :)
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 to show/hide rows based on a range of dates Eric F. Excel Programming 0 June 2nd 08 06:00 PM
Macro to Hide rows based on value of column F Scott Marcus Excel Discussion (Misc queries) 10 October 27th 06 11:57 PM
Macro to hide and unhide based on criteria [email protected] Excel Discussion (Misc queries) 1 June 5th 06 08:05 PM
Macro to hide rows based on a zero value in a particular cell Peter Excel Programming 2 July 29th 04 03:19 AM
macro to hide rows based on formula? Scott T. Lindner Excel Programming 5 October 20th 03 01:40 PM


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