PDA

View Full Version : hide/unhide columns



lior03
01-14-2006, 05:02 AM
hello
i am trying to built a macro to enable the user choose between hide or unhide a column.
using select case the user can "toggle" between both
possibilities.whats wrong?

Sub hider()
Dim hide As Integer
MsgBox "to hide a column press 1" & vbLf & _
"to unhide column press 2"
InputBox ("select hide/unhide")
Select Case hide
Case 1
Selection.EntireColumn.Hidden = True
Case 2
Selection.EntireColumn.Hidden = False
End Select
End Sub


thanks

Bob Phillips
01-14-2006, 05:37 AM
Sub hider()
Dim hide As Integer
hide = InputBox("to hide a column press 1" & vbLf & _
"to unhide column press 2", "select hide/unhide")
Select Case hide
Case 1
Selection.EntireColumn.Hidden = True
Case 2
Selection.EntireColumn.Hidden = False
End Select
End Sub


But there is a problem here. Once it is hidden how do you select it to unhide?

mdmackillop
01-14-2006, 07:24 AM
Once it is hidden how do you select it to unhide?

F5


For a toggle function without the need of an input box, try the following
Sub Hiding()
Dim cel as range
For Each cel In Intersect(Selection, ActiveCell.EntireRow)
If cel.EntireColumn.Hidden = True Then
Selection.EntireColumn.Hidden = False
Exit Sub
End If
Next
Selection.EntireColumn.Hidden = True
End Sub