1 button to do 2 things

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
Hi everyone...I'd like one button that when pressed will either unhide rows if they are hidden, or hide them if they are unhidden...I can't seem to get the logic of it down...Here is my fumbling attempts so far:

Code:
Private Sub CommandButton1_Click()

If Columns("H:O").EntireColumn.Hidden = False Then
    Module1.unHideCol
End If

If Columns("H:O").EntireColumn.Hidden = True Then
    Module1.HideCol
End If

End Sub

Any ideas?

Thanks,

Dave M.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

TryingToLearn

Well-known Member
Joined
Sep 10, 2003
Messages
723
Sub togglehide()
Columns("H:O").EntireColumn.Hidden = Not Columns("H:O").EntireColumn.Hidden
End Sub
 

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
Sweet! What a simple answer!!! I really appreciate it!

Have a good day,

Dave M. (y)
 

TryingToLearn

Well-known Member
Joined
Sep 10, 2003
Messages
723
No problem. I'm simply paying back with what I've learned here in the past several months and giving those that helped me more time to help others!
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456

ADVERTISEMENT

Hi Davers,
If you’re using a Forms toolbar button for that, another approach
might be something like this:

Sub HideUnhide()
ActiveSheet.Shapes("Button 1").Select
Select Case Selection.Characters.Text
Case "Hide"
Columns("H:O").EntireColumn.Hidden = True
ActiveSheet.Shapes("Button 1").Select
Selection.Characters.Text = "Unhide"
Case "Unhide"
Columns("H:O").EntireColumn.Hidden = False
ActiveSheet.Shapes("Button 1").Select
Selection.Characters.Text = "Hide"
Case Else
End Select
[A1].Select
End Sub

You’ll have to supply the button number and where the
active cell should be when it’s done.
(You'll also need to give the button the text Hide)

This help?
Dan
 

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
Thanks for the reply HalfAce...I appreciate it. I'll have to file away your code away for a later date though....after all the work that went into this workbook...I made the mistake of mentioning that they might want to go the database route as opposed to the spreadsheet route... :eek: Now they want me to design something in Access...sigh :rolleyes:


Thanks again,

Dave :p
 

KennyC

New Member
Joined
Jul 23, 2003
Messages
42
Hi,

Or if someone needs to do a range of columns to hide.

Code:
Sub togglehide()
Range("B:B,D:D").EntireColumn.Hidden = Not Range("B:B,D:D").EntireColumn.Hidden
End Sub

Cheerz :) :wink: :biggrin:
 

KennyC

New Member
Joined
Jul 23, 2003
Messages
42
Davers said:
...I made the mistake of mentioning that they might want to go the database route as opposed to the spreadsheet route... :eek: Now they want me to design something in Access...sigh :rolleyes:


Thanks again,

Dave :p

Hi Davers,

Silly boy........ :oops: :eek: :rolleyes:

Just think, you might have to start visiting the Mr.Excel Access Forum.

Cheerz :) :wink: :biggrin:
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,334
Messages
5,769,473
Members
425,553
Latest member
chrisc297

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top