LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default macro to hide columns with zero values?

I believe the code below will work for you. It will examine all used cells
on the row on a selected sheet where a cell is selected and hide all columns
with an empty cell or a zero value cell on that row. In your example, you'd
select any cell in row 202 of the sheet and then run the macro.

Sub HideZeroTotalColumns()
'this works with the active sheet
'in whatever book, and all you need
'to do is select the book, sheet and
'a cell in the "total" row to then
'hide all columns with a zero total

Dim anyWS As Worksheet
Dim anyTotalRow As Range
Dim anyCell As Range
Set anyWS = ActiveSheet
Set anyTotalRow = anyWS.Range(Cells(ActiveCell.Row, 1).Address, _
Cells(ActiveCell.Row, _
anyWS.Cells(ActiveCell.Row, Columns.Count). _
End(xlToLeft).Column))
'improve performance speed
Application.ScreenUpdating = False
'unhide in case was hidden and is now
'non-zero
anyTotalRow.Columns.EntireColumn.Hidden = False
For Each anyCell In anyTotalRow
If IsEmpty(anyCell) Or anyCell = 0 Then
anyCell.EntireColumn.Hidden = True
End If
Next
Set anyTotalRow = Nothing
Set anyWS = Nothing
End Sub


"K Dawson" wrote:

I'm relatively new to VBA and need to create a macro to hide columns with
zero values. The workbook has 36 sheets, each sheet has columns B:CR and 202
rows. Row 202 is the sum of the respective column.
I'd like to run the macro in a separate workbook so I can use it for other
similar workbook situations.
Any suggestions would be greatly appreciated!

 
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 hide rows with zero values in columns K Dawson Excel Discussion (Misc queries) 2 March 23rd 10 03:00 PM
Macro to Hide columns whatzzup Excel Discussion (Misc queries) 3 October 23rd 09 01:39 PM
Using Macro to Hide Rows with Certain Values Gap from Target[_2_] Excel Discussion (Misc queries) 2 July 17th 09 12:57 PM
Need a macro to hide certain columns Dallman Ross Excel Discussion (Misc queries) 12 October 19th 06 05:58 PM
macro to hide columns Shooter Excel Worksheet Functions 2 September 27th 05 09:04 PM


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