Button ( form Control ) - to enable & disable based on excel cell value

Rohith1324

Board Regular
Joined
Feb 27, 2018
Messages
114
I have an excel sheet where in C7 cell we will have the values. ( End user to key in ) the values can be "E" or "B"

when the value in C7 is - "E" then the Button1(form Control ) to be enabled.
when the value in C7 is - "B" then the Button1(form Control ) to be disabled

please support
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi there

What about:

Goes to sheet code:

VBA Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If ActiveSheet.Range("C7") = "E" Then
        Call disable_button_1
    ElseIf ActiveSheet.Range("C7") = "B" Then
        Call activate_button_1
    End If
End Sub

Goes into standard module:

VBA Code:
Option Explicit
Sub disable_button_1()
    Dim myshape As Shape: Set myshape = ThisWorkbook.Worksheets("Sheet1").Shapes("Button 1")
    With myshape
       .ControlFormat.Enabled = False    '---> Disable the button
       .TextFrame.Characters.Font.ColorIndex = 15    '---> Grey out button label
    End With
End Sub
Sub activate_button_1()
    Dim myshape As Shape: Set myshape = ThisWorkbook.Worksheets("Sheet1").Shapes("Button 1")
    With myshape
       .ControlFormat.Enabled = True    '---> Enable the button
       .TextFrame.Characters.Font.ColorIndex = 1    '---> Highlight button label
    End With
End Sub
 
Upvote 0
Solution
Hi there

What about:

Goes to sheet code:

VBA Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If ActiveSheet.Range("C7") = "E" Then
        Call disable_button_1
    ElseIf ActiveSheet.Range("C7") = "B" Then
        Call activate_button_1
    End If
End Sub

Goes into standard module:

VBA Code:
Option Explicit
Sub disable_button_1()
    Dim myshape As Shape: Set myshape = ThisWorkbook.Worksheets("Sheet1").Shapes("Button 1")
    With myshape
       .ControlFormat.Enabled = False    '---> Disable the button
       .TextFrame.Characters.Font.ColorIndex = 15    '---> Grey out button label
    End With
End Sub
Sub activate_button_1()
    Dim myshape As Shape: Set myshape = ThisWorkbook.Worksheets("Sheet1").Shapes("Button 1")
    With myshape
       .ControlFormat.Enabled = True    '---> Enable the button
       .TextFrame.Characters.Font.ColorIndex = 1    '---> Highlight button label
    End With
End Sub
Great....this works....thank you so much Jimmy..
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,939
Latest member
Leon Leenders

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