How to hide or unhide a Command Button based on specified cell value in Excel?
Supposing you are using a Command Button to trigger a VBA script in your worksheet. When the VBA script is unused in some cases, you need to make the Command Button hidden instead of displaying in the worksheet. And display it again when the VBA script is needed. This article is talking about hiding or showing a Command Button based on a specified cell value in Excel. Please do as follows.
You can run the below VBA code to hide or unhide a Command Button based on specified cell value in Excel.
1. Right click the sheet tab which contains the Command Button you need to show hide, then click View Code from the right-clicking menu.
2. In the popping up Microsoft Visual Basic for Applications window, copy and paste the below VBA code into the Code window.
VBA code: Hide or unhide a Command Button based on specified cell value
Private Sub Worksheet_Change(ByVal Target As Range) Application.ScreenUpdating = False If Cells(1, 1).Value <> "1" Then Me.CommandButton1.Visible = True Else Me.CommandButton1.Visible = False End If Application.ScreenUpdating = True End Sub
Note: in the code, Cells(1, 1), 1 and CommandButton1 indicate that the CommandButton1 will be hidden when cell A1 contains number 1, and displayed if cell A1 contains any other values except number 1. See below screenshot. And you can change them based on your need.
- How to copy Combo Box value to active cell in Excel?
- How to display date format in combo box output in Excel?
- How to open a specific worksheet by the selected value of a Combo Box in Excel?
- How to prevent or disable typing in a combo box in Excel?
- How to tab out of combo box to select specific cell in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!