Hide unhide non-contiguous columns

  • Thread starter Thread starter Saintsman
  • Start date Start date
S

Saintsman

I use the following code to hide/unhide a range of cells using a tick box
With Columns("O:W")
.Hidden = Not .Hidden
End With

I want to do exactly the same for columns G,J,P,R ie if they are hidden then
unhide them, if they are not hidden then hide them
Any help appreciated
 
Try this

If Not Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden Then
Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden = True
End If

Mike
 
How do I unhide them using the same control?

Mike H said:
Try this

If Not Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden Then
Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden = True
End If

Mike
 
Sub togglehiddencolumns()
Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden = Not _
Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden
End Sub
 
Hi,

This makes it into a toggle of hide/unhide

If Not Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden Then
Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden = True
Else
Range("G:G,J:J,P:P,R:R").EntireColumn.Hidden = False
End If

Mike
 
OR
Sub togglehiddencolumns()
With Range("G:G,J:J,P:P,R:R").EntireColumn
.Hidden = Not .Hidden
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top