Hide columns based on cells = 0

DoosanRuss

New Member
Joined
Aug 3, 2010
Messages
25
Good Afternoon All

I've found this code on the tin-ter-web and it works

Code:
Private Sub Worksheet_Calculate()
Application.ScreenUpdating = False
Dim c As Range
    For Each c In Range("K8:CD8")
        c.EntireColumn.Hidden = (c.Value = 0)
    Next c
Application.ScreenUpdating = True
End Sub

however my Range is K8 to CD12, when i change the code to CD12 it hides all the columns regardless of cells containing data greater than Zero.

What i would like the code to do is look at cells K8, K9, K10, K11 & K12 if they all equal "0" i want Excel to hide the column
If any of those cells are greater than "0" then the column stays unhidden.

then move on to the next column J8, J9 ... etc

All help gratefully recieved

BR

Russ
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Have no idea what the tin-ter-web is.

Column J is not in your specified range.

How are the values in your range being changed? Manually or by formula?
 
Upvote 0
Oh Jeez! i meant 'L' not J good god.. hard day methinks, never good when you can't do your abc's

The Range is being changed by formula

BR

Russ

P.S tin-ter-web is internet, sorry i'd just been speaking to a Mancunian
 
Upvote 0
Code:
Private Sub Worksheet_Calculate()
Dim c As Range
Application.EnableEvents = False
    For Each c In Range("K8:CD8")
        c.EntireColumn.Hidden = Application.WorksheetFunction.CountIf(c.Resize(5), 0) = 5
    Next
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,741
Members
449,050
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top