hiding Command Button

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
Is there a way to hide the command button after it's already done what it needs to do. For instance, CommandButton1 just runs a macro to format a Worksheet. After the worksheet is formatted, the button now hovers over some of the data. I know how to set the option so it doesn't print; but as far as on the screen, can I hide it by a simple code at the end of the macro?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi There

You could use something like


Code:
Sheets("sheet name").CommandButton1.Visible = xlHidden

Where you would just change CommandButton to the name of the object you want to hide and sheet name to the sheet you want to hide it from, alternatively this could be written as ActiveSheet. If you wanted re show it at a later point you could use xlVisible in another macro.

Hope this helps


Dave
 
Upvote 0
that helped. Realize now why it didn't work the 1st time...I wrote everything the same except xlHidden, I wrote False.
 
Upvote 0
Also need some kind of statement that says if while commandbutton1 is hidden if data is pasted into worksheet, to unhide commandbutton.
 
Upvote 0
you could use worksheet_change like this in the Sheet code for the sheet in question.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("Sheet1").CommandButton1.Visible = xlVisible
End Sub

Hope this helps


Dave
 
Upvote 0
I tried that already, and basically the button becomes invisible with the slightest change. If user just selects a cell, button appears.

I'm looking for more of an if statement maybe in this same place that says if cell A2 has changed or is not blank then to unhide commandbutton

I'm not very good at if statements in macros
 
Upvote 0
Try setting the xlVisible line in BeforeDoubleClick instead of Change and ask users to double click the sheet to run your macro?

I too am not too good with statements, I tried a few If statements that didn't work. Hopefully one of the wizards here might come up with a better suggestion.

Kind Regards

Dave
 
Upvote 0
Thanks dave for your help and ideas. I really do need an if statement though. So if anyone else knows of a way to unhide button based off worksheet recognizing that new data was pasted in or something of that nature, that'd be great.
 
Upvote 0
Have you tried using Range("A2").IsNumber in your If statement?

I'm playing with it now so if I find a solution I'll let you know


Dave
 
Upvote 0
Try this changing as required to fit your needs

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case IsNumeric(A2)
    Case True
        Sheets("Sheet1").CommandButton1.Visible = xlVisible
    Case False
        Sheets("Sheet1").CommandButton1.Visible = xlHidden
End Select
End Sub

I knew there was some method.


HTH




Dave
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,580
Members
449,039
Latest member
Arbind kumar

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
Back
Top