Disable form button based on cell value

tezza

Active Member
Joined
Sep 10, 2006
Messages
375
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
  2. Web
Hi

How would I go about disabling a Form button if the value on sheet 1 at Cell M29 is filled?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
VBA Code:
Private Sub UserForm_Activate()
    If Range("M29").Value <> "" Then
        CommandButton1.Enabled = False
    Else
        CommandButton1.Enabled = True
    End If
End Sub
 
Upvote 0
VBA Code:
Private Sub UserForm_Activate()
    If Range("M29").Value <> "" Then
        CommandButton1.Enabled = False
    Else
        CommandButton1.Enabled = True
    End If
End Sub
That doesn't appear to run. It's just runs as normal.

I changed CommandButton1 to NextNo as that's the macro name. Is that right?
 
Upvote 0
This works, however, it hides the button instead of disabling it:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
      If Range("M29") <> "" Then
          Buttons("Button 12").Visible = False
      ElseIf Range("M29") = "" Then
      Buttons("Button 12").Visible = True
End If
End Sub

I didn't realise it also had to be on the Worksheet and not in a module.
 
Upvote 0
Not sure how to disable it but as a workaround, In the macro assigned to that button you can skip the code

VBA Code:
Sub Button1_Click()
    'Put this code above your original code
    If Range("M29") <> "" Then Exit Sub
    
    'Your original code goes here
    
End Sub
 
Upvote 0
Not sure how to disable it but as a workaround, In the macro assigned to that button you can skip the code

VBA Code:
Sub Button1_Click()
    'Put this code above your original code
    If Range("M29") <> "" Then Exit Sub
   
    'Your original code goes here
   
End Sub
Yep, that works, thank you :)
 
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,464
Members
449,163
Latest member
kshealy

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