Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Hide rows with zero balances

Will column A be the same length as columns D:H?

Will you have columns past column H?

Assuming answer to both above is Yes.............

Sub test()
Dim lrow As Long
Dim prow As Range
Dim StartRow As Long
Dim EndRow As Long
Sheets("Sheet6").Activate 'adjust sheetname to suit
Cells.EntireRow.Hidden = False
StartRow = 1
Range("A1").Select
EndRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = EndRow To StartRow Step -1
Set prow = Range(Cells(i, "D"), Cells(i, "H"))
With prow
If Application.CountIf(prow, "0") = 5 Then 'D:H is 5 columns
.EntireRow.Hidden = True
End If
End With
Next
Range("A1").Select
End Sub


Gord
On Fri, 7 Aug 2009 10:34:02 -0700, Tasha
wrote:

Hi Gord....wondering if you can look at this for me? Was working fine until
I added a column, now isn't...Want it to hide rows if columns D-H have 0's in
them. Also, need this changed so it will only do this on the active
worksheet, not all worksheets in the workbook....can you help me? Would
really appreciate it!!!

Dim numcols As Long
Dim lrow As Long
Dim prow As Range
Dim StartRow As Long
Dim EndRow As Long
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
Cells.EntireRow.Hidden = False
StartRow = 1
Range("A1").Select
EndRow = Cells(Rows.Count, 1).End(xlUp).Row
LastCol = Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Column
For i = EndRow To StartRow Step -1
Set prow = Range(Cells(i, "D"), _
Cells(i, LastCol))
prow.Select
numcols = prow.Columns.Count
If Application.CountIf(prow, "0") = numcols Then
prow.EntireRow.Hidden = True
End If
Next
Range("A1").Select
Next ws

"Gord Dibben" wrote:

Variable columns?

You mean some rows have fewer or more columns than others?

This macro assumes the same number(numcols) of used columns in each row.

Sub hide_zero_rows()
Dim numcols As Long
Dim lrow As Long
Dim prow As Range
Dim StartRow As Long
Dim EndRow As Long
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
Cells.EntireRow.Hidden = False
StartRow = 1
Range("A1").Select
EndRow = Cells(Rows.Count, 1).End(xlUp).Row
LastCol = Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Column
For i = EndRow To StartRow Step -1
Set prow = Range(Cells(i, "B"), _
Cells(i, LastCol))
prow.Select
numcols = prow.Columns.Count
If Application.CountIf(prow, "0") = numcols Then
prow.EntireRow.Hidden = True
End If
Next
Range("A1").Select
Next ws
End Sub


Gord

On Mon, 2 Mar 2009 14:35:04 -0800, KevinK
wrote:

All columns must have a zero. Actually there are at least 11 columns excl
the first with text. The rows will be variable. Is it possible to make the
columns variable as well?

Thanks
KevinK

"Gord Dibben" wrote:

All 9 columns have a zero or any of the 9 have a zero?

Will the number of "about 100 rows" be variable?

Please respond so's we can tailor code to suit for all sheets in a workbook.


Gord Dibben MS Excel MVP

On Sun, 1 Mar 2009 23:18:01 -0800, KevinK
wrote:

Hi Roger

I found this macro very useful, except it is hiding rows with values in
them. My worksheet has approx ten columns with text in the first column and
numbers/percentages in the next 9 columns. I want it to hide the rows with
zero values after the first column. There are about 100 rows in each
tab/worksheet. Also, how do I get the macro to run across all
tabs/worksheets in the same file?

Thanks
Kevin

"Roger Govier" wrote:

Hi

I don't think you can achieve that with a function.
The following VBA macro will achieve what you want

Sub Hiderows()
Dim lr As Long, i As Long
With ActiveSheet
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
If Cells(i, 3) = 0 And Cells(i, 4) = 0 Then
Cells(i, 1).EntireRow.Hidden = True
End If
Next
End With
End Sub

And to make the hidden rows visible again, run this macro


Sub Showrows()
Dim lr As Long, i As Long
With ActiveSheet
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
If Cells(i, 3) = 0 And Cells(i, 4) = 0 Then
Cells(i, 1).EntireRow.Hidden = False
End If
Next
End With
End Sub

You can copy the code and paste it into your Visual Basic Editor
(VBE) in a Standard Module located in your file.

To do this,

Alt + F11 (open VBE)
Ctrl + R (open Project Explorer)
Select the file name on the left
Insert Module
Paste code in Module

David McRitchie has lots of useful help on his site to get you started
with installing code, at
http://www.mvps.org/dmcritchie/excel/install.htm
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Then on your sheet with the data, just choose
ToolsMacroselect either to Hiderows or ShowrowsRun

--
Regards

Roger Govier


"LennieLou" wrote in message
...
Hi, I have created a report by linking the worksheet with the
balances to a
new worksheet as such: Account Name, Account Number, Dr & Cr. The Dr
and Cr
columns contain the value of the calculation performed on the previous
worksheet. eg C8=CALCULATIONS!O10. I am looking for a function/formula
that
will hide a row when the Dr(C8) and Cr(D8) balances are zero?

Any help would be appreciated.









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
Pivot Tables - Exclude Rows With Zero Balances bobs Excel Discussion (Misc queries) 2 January 10th 08 01:53 PM
Hide Rows shail Excel Worksheet Functions 2 September 28th 06 11:20 PM
HOW DO I AUTOMATICALLY DELETE ROWS WITH ZERO BALANCES? suec4 Excel Worksheet Functions 1 August 25th 06 03:17 PM
Hide Rows - copy and paste only rows that show Access101 Excel Worksheet Functions 3 March 1st 06 12:39 AM
How to link endings balances to beginning balances on different sh judyskiskd Excel Worksheet Functions 1 October 28th 04 07:21 PM


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

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"