View Full Version : Solved: Toggle:Hide/Unhide Columns on 2 separate sheets
klutz
07-15-2009, 08:39 AM
Is it possible to code in a Toggle switch to hide and unhide columns on two different sheets within the same workbook?
 
Can anybody show me how?:thumb 
 
I presently have on toggle on sheet1 that hides a set of columns while unhiding another set, I would like to do the same on sheet 2 on another set of columns.
 
Thanks....
mdmackillop
07-15-2009, 09:10 AM
Can you post your present code?
Bob Phillips
07-15-2009, 09:35 AM
Just extend the code prefacing the range with the worksheet object
With Worksheets("Sheet1").Rows("1:10")
    .Hidden = Not .Hidden
End With
With Worksheets("Sheet2").Rows("1:10")
    .Hidden = Not .Hidden
End With
klutz
07-15-2009, 10:06 AM
Can you post your present code?
 
This actually comes modified form onof your previous macro mdmackillop
This code is in sheet 1 with one toggle switch.
 
If ToggleButton1.Value = True Then
 
'This area contains the things you want to happen
'when the toggle button is not depressed
    Columns(30).EntireColumn.Hidden = False
    Columns(40).EntireColumn.Hidden = True
    Columns(66).EntireColumn.Hidden = False
    Columns(73).EntireColumn.Hidden = False
    Columns(67).EntireColumn.Hidden = True
    Columns(74).EntireColumn.Hidden = True
    
    Else
'This area contains the things you want to happen
'when the toggle button is depressed
    Columns(30).EntireColumn.Hidden = True
    Columns(66).EntireColumn.Hidden = True
    Columns(73).EntireColumn.Hidden = True
    Columns(40).EntireColumn.Hidden = False
    Columns(67).EntireColumn.Hidden = False
    Columns(74).EntireColumn.Hidden = False
    
End If
End Sub
 
 
 
And this code is in one sheet 2  with another toggle switch.
 
If ToggleButton1.Value = True Then
 
'This area contains the things you want to happen
'when the toggle button is not depressed
  
    Columns(7).EntireColumn.Hidden = False
    Columns(16).EntireColumn.Hidden = False
    Columns(8).EntireColumn.Hidden = True
    Columns(17).EntireColumn.Hidden = True
Else
'This area contains the things you want to happen
'when the toggle button is depressed
    
    Columns(7).EntireColumn.Hidden = True
    Columns(16).EntireColumn.Hidden = True
    Columns(8).EntireColumn.Hidden = False
    Columns(17).EntireColumn.Hidden = False
    
End If
 
End Sub
 
I would like to be able to combined the two with the toggle switch on sheet one.:dunno
Bob Phillips
07-15-2009, 10:27 AM
With Worksheets("Sheet1")
        
        .Columns(30).Hidden = Not ToggleButton1.Value
        .Columns(40).Hidden = ToggleButton1.Value
        .Columns(66).Hidden = Not ToggleButton1.Value
        .Columns(73).Hidden = Not ToggleButton1.Value
        .Columns(67).Hidden = ToggleButton1.Value
        .Columns(74).Hidden = ToggleButton1.Value
     
    End With
     
    With Worksheets("Sheet2")
    
        .Columns(7).Hidden = Not ToggleButton1.Value
        .Columns(16).Hidden = Not ToggleButton1.Value
        .Columns(8).Hidden = ToggleButton1.Value
        .Columns(17).Hidden = ToggleButton1.Value
    End With
klutz
07-15-2009, 10:43 AM
Thanks again great distant collaborators. Works DANDY..
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.