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?
 
You could try:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Range("A1").Address Then
        MsgBox "Your Code Here"
    End If
End Sub
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Okay, I got the Button to disappear when there's no data in Cell A1 by using this code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case IsEmpty(A1)

    Case True
        Sheets("ShippedQty-SummarybyYr").CommandButton1.Visible = xlHidden
    Case False
        Sheets("ShippedQty-SummarybyYr").CommandButton1.Visible = xlVisible
End Select
End Sub
However, shouldn't that also show the button if there were something in cell A1?

the Select Case IsNumeric(A1) didn't work because if/when there is something in A1 it's usually text.
 
Upvote 0
Good point, you may need to use Select Case twice in that case. one for IsEmpty, one for HasValue. It is at this point I start getting lost. I'll play some more for you and post any findings

Cheers


Dave
 
Upvote 0
Dufus, I'm not sure, but I tried this code and then clicked the button and it tried to continue the Macro regardless that cell A1 was empty without giving me the prompt of what I typed between the quotations.

do you think I did something wrong or didn't understand you completely?

Here's how I wrote the code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Range("A1").Address Then
        MsgBox "You must first copy/paste data from Viper Drill-Down"
    End If
End Sub

Looks like I'm supposed to tell it what Address is?
I'm not sure. Please help
 
Upvote 0
Dufus, I figured out what your code was doing. It would be if the user was actually physically changing something in A1. It's the opposite, I want it to work like if there is nothing in A1 (or null) and user presses commandbutton1 it would bring up this error message and end the macro
 
Upvote 0
Hi

I have come up with this so far, it doesn't work however I feel you might be able to tweak it to work or someone more suitable qualified might get it to work

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

Hopefully you can resolve this issue. I probably have the same knowledge of VBA as you hence my basic responses. I will continue to watch so as I can stick in my 2 pence in where its worth


Good Luck


Dave
 
Upvote 0
aka_krakur,

Sorry, I thought you were looking for a simple way to hide and unhide the button that hovered in your way. In my code you would trigger the hiding and unhiding any time A1 changed. Even restricting the possible entries in A1 using [Data][Validation] wouldn't really be necessary since you could just put a message "Change the cell contents to Hide or Unhide the Button" in the cell.
 
Upvote 0
Still needing some assistance with this. If anyone can help. Here's a brief summary:
CommandButton1.
When Workbook is open CommandButton1 appears.
User is supposed to copy/paste data over existing data.
Then they press CommandButton1 to run a macros that formats the data automatically for them.
Am able to hide CommandButton1 after macros is ran no problem.
1. Problem is, I need to unhide it based off of if user copied/pasted data back again
2. Was able to write a code that if A1 is empty, if user presses CommandButton1 it will just send up a message box reminding them that they have to copy/paste data first. Then it ends the macro until they do so.

Please help if you can....thanks
 
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,696
Members
449,464
Latest member
againofsoul

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