View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default hide and show columns using one control button

Sub Hide_TY()
Dim btn as Button
set btn = Activesheet.Buttons(application.Caller)
If Range("I1").Entirecolumn.Hidden = False then
Range("F1,I1").EntireColumn.Hidden = True
Range("E1:G1,H1:J1").Entirecolumn.Hidden = False
btn.Caption = "Show F and I"
else
Range("E1:G1,H1:J1").Entirecolumn.Hidden = True
Range("F1,I1").EntireColumns.Hidden = False
btn.Caption = "Show E:G and H:J"
End if
End Sub

--
Regards,
Tom Ogilvy


"dreamkeeper" wrote in message
oups.com...
Hi.
I am great in excel but not so great in macros

I am creating a rperot that has "this year", "plan", and "last year"
columns. I want to be able to hide and show specific columns like
"this year" by pressing a "hide ty" button and once it is hidden, have
that same button now say "show this year" and then show this year
columns.

I have created two button controled macros to do the above but I want
to only have one button that toggles and the text changes from hide to
show.

I have an example of this that I can send to someone.

thank you for your help...I am a rookie!
Sub Hide_TY()
Range("F:F,I:I").Select
Range("I1").Activate
Selection.EntireColumn.Hidden = True
End Sub

Sub unhide_TY()
Range("E1:G1,H1:J1").Select
Range("H1").Activate
Selection.EntireColumn.Hidden = False
Range("F10").Select
End Sub