Hide unhide non-contiguous columns

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
 
M

Mike H

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
 
S

Saintsman

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
 
D

Don Guillett

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
 
M

Mike H

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
 
D

Don Guillett

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

Top