• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

I'm trying to hide columns in excel when no conditional highlighting is present in the column

bts1969

New Member
I'm trying to hide columns in Excel when NO conditional highlighting (yellow color cell fill) is present in the column and unhide them if there is any cell in the column with yellow color cell fill. This VBA here is doing the reverse of what I need:

Option Explicit
Sub show_hide_columns_color()
Dim cell As Range
Dim button_color As Long

For Each cell In Range("H2:J18") 'Change range to suit
If cell.Interior.Color = 65535 Then
If Columns(cell.Column).EntireColumn.Hidden Then
Columns(cell.Column).EntireColumn.Hidden = False
Else
Columns(cell.Column).EntireColumn.Hidden = True
End If
End If
Next
End Sub
 
@bts1969

Code:
Option Explicit
Sub show_hide_columns_color()
Dim cell As Range
Dim button_color As Long

For Each cell In Range("H2:J18") 'Change range to suit
If Not cell.Interior.Color = 65535 Then
If Columns(cell.Column).EntireColumn.Hidden Then
Columns(cell.Column).EntireColumn.Hidden = False
Else
Columns(cell.Column).EntireColumn.Hidden = True
End If
End If
Next
End Sub

hope this may work as intended.
 
Back
Top