Enable button if specific cells have values

bobbieatendido

New Member
Joined
Jul 13, 2016
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi,

May i please ask for help on this excel problem i have?

I have 3 buttons, which already have macro's.

I need these buttons to only be clickable when all cells have values in them.

Note: 9 are dropdown lists and 5 are manually entered.

Dropdown: C4, C6, (C14 D14 E14 F14 G14), M8 and M12
Manually entered: C8, C10, (C12 E12) and M1
 

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"
Hi welcome to Forum.

You don't give much detail but I am guessing your buttons are ActiveX CommandButtons on your worksheet?

You could try something like this & see if does what you want:


Place code in your worksheets code page:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim RequiredCells As Range
    Dim Enabled As Boolean
    
    Set RequiredCells = Me.Range("C4,C6,C8,C10,C12,C14:G14,E12,M1,M8,M12")
    
    If Not Intersect(Target, RequiredCells) Is Nothing Then
    
    Enabled = CBool(Application.CountA(RequiredCells) = RequiredCells.Count)


    
    Me.CommandButton1.Enabled = Enabled
    Me.CommandButton2.Enabled = Enabled
    Me.CommandButton3.Enabled = Enabled
    
    Else
    Set RequiredCells = Nothing
    End If
    
End Sub

Dave
 
Last edited:
Upvote 0
Hi Dave,

Thank you for your reply and welcome.


My sheet looks like this: https://img42.com/Eu8BT


The buttons are, Button (Form Control)
I'm not really good at excel macros so what i did was, i duplicated the sheet to a new excel, recorded a macro then copied that macro code to the Button (Form Control). Is it different to an ActiveX Commandbutton?


I also renamed my button to record, print and new. do i change:


Me.CommandButton1.Enabled = Enabled
Me.CommandButton2.Enabled = Enabled
Me.CommandButton3.Enabled = Enabled


to


Me.record.Enabled = Enabled
Me.print.Enabled = Enabled
Me.new.Enabled = Enabled


Thank you so much for the help. :)
 
Upvote 0
Also, do i put the code to,
Developer > Visual Basic > (Sheetname) > then paste the code?

Sorry for too many questions.

Thank you again.
 
Upvote 0
Nevermind, i got it:

i added this to the module:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">Public Function BlankCells() As Boolean
Dim c As Range
BlankCells = False
For Each c In ActiveSheet.Range("C4,C6,C14,D14,E14,F14,G14,M8,M12,C8,C10,C12,E12,M1")
If IsEmpty(c) Then
BlankCells = True
Exit Function
End If
Next c
End Function</code>
and this to very top of each individual macro, except the delete all. :

<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;"> If BlankCells Then Exit Sub</code>
 
Upvote 0
Glad figured something for yourself but can do what you want without looping:

Code:
Function BlankCells() As Boolean
    Dim RequiredCells As Range
    Set RequiredCells = Range("C4,C6,C8,C10,C12,C14:G14,E12,M1,M8,M12")
    BlankCells = CBool(Application.CountA(RequiredCells) = RequiredCells.Count)
End Function

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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