toggle button in excel

G

Guest

I would like to use a toggle button to hide and unhide several columns and
rows.
The first thing I did was to create 2 macros 1 to hide and other to unhide.
But now I would like to link those macros in a toggle button. I have tried
but no results. Is any idea around? Thanks
 
G

Guest

you can hide or show columns & rows by setting Hidden property True or False
If you want to toggle it, you need to use Not operator as following:
rng.EntireRow.Hidden = Not rng.EntireRow.Hidden
rng.EntireColumn.Hidden = Not rng.EntireColumn.Hidden

where rng is a Range object variable.
 
G

Guest

See code below..

Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Hide" Then
Columns("G:G").Select
Selection.EntireColumn.Hidden = True
CommandButton1.Caption = "UnHide"
Else
Columns("G:G").Select
Selection.EntireColumn.Hidden = False
CommandButton1.Caption = "Hide"
End If
End Sub
 
G

Guest

Thanks for your help Timebird I appreciate it....
This helps me with the columns (consecutive data), but I have non
consecutive rows. I have data on every row, some of those rows (non
consecutive) have data grouped (it have the cross icon on the upperleft
corner to hide & unhide) What i'm trying to do is use a button instead of the
cross icon that appear when you group data with a row or column.
Suggestions? Thanks
 
G

Guest

Thanks Himani... it helps me on how to program the button.. But I do not
have consecutive rows data that I need to hide.. it represents my biggest
problem...
Because the sheet is being updated by adding information when I use the
upperleft 1,2 button it will hide or unhide all the information.
 

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