ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Can I automatically hide a column with zero values in Excel (https://www.excelbanter.com/excel-discussion-misc-queries/193722-can-i-automatically-hide-column-zero-values-excel.html)

David Hainsworth

Can I automatically hide a column with zero values in Excel
 
I have a large spreadsheet which will be populated based on the selection
from a drop down list box. The values populated will contain alot of zero
values which I have blanked out using the tools/options functionality but I
would like to automatically hide the column if all values within a range in
that column are zero. Can this be done using advanced filter ? if so how ...
any other suggestions ?

JMay

Can I automatically hide a column with zero values in Excel
 
I use the following Macro in a Workbook of mine.
Before running the Macro (Which is in a Standard Code module)
Click and sellect the Column-Header (First to Last) of your data;
Allows for say Column C thru Column S (Columns A & B Blank)

Try this on a COPY of your WB first

Sub HideColumnsWithZeroValues()
Dim i As Integer
Dim ColCount As Integer
Application.ScreenUpdating = False
StrCol = Selection(1).Column
ColCount = Selection.Columns.Count + StrCol - 1
With Selection
For i = StrCol To ColCount
If Application.WorksheetFunction.Sum(Columns(i)) = 0 Then
Columns(i).EntireColumn.Hidden = True
End If
Next i
End With
Application.ScreenUpdating = True
End Sub

Good Luck

"David Hainsworth" wrote:

I have a large spreadsheet which will be populated based on the selection
from a drop down list box. The values populated will contain alot of zero
values which I have blanked out using the tools/options functionality but I
would like to automatically hide the column if all values within a range in
that column are zero. Can this be done using advanced filter ? if so how ...
any other suggestions ?



All times are GMT +1. The time now is 09:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com