ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide unhide non-contiguous columns (https://www.excelbanter.com/excel-programming/421646-hide-unhide-non-contiguous-columns.html)

Saintsman

Hide unhide non-contiguous columns
 
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

Mike H

Hide unhide non-contiguous columns
 
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

"Saintsman" wrote:

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


Saintsman

Hide unhide non-contiguous columns
 
How do I unhide them using the same control?

"Mike H" wrote:

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

"Saintsman" wrote:

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


Don Guillett

Hide unhide non-contiguous columns
 
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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Saintsman" wrote in message
...
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



Mike H

Hide unhide non-contiguous columns
 
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

"Saintsman" wrote:

How do I unhide them using the same control?

"Mike H" wrote:

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

"Saintsman" wrote:

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


Don Guillett

Hide unhide non-contiguous columns
 
OR
Sub togglehiddencolumns()
With Range("G:G,J:J,P:P,R:R").EntireColumn
.Hidden = Not .Hidden
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Saintsman" wrote in message
...
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




Saintsman

Hide unhide non-contiguous columns
 
Thanks to all of you - lots of options for me to pick from

Saintsman

"Don Guillett" wrote:

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Saintsman" wrote in message
...
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






All times are GMT +1. The time now is 02:43 PM.

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