Run Macro Only If 4 Cells Are Filled In By User In VBA

C

Celtic_Avenger

Hi again.

I have a sheet where the user is required to answer 4 question befor
continuing.
The user has to enter data into 4 cells before being allowed to pres
the continue button.

I have allready created the button to run the next operation whe
pressing "Continue", but I would like the button to be dis-enable
until all 4 cells are completed.

The cell refferences are:

E6, E8, E10, and E12

The button is still currently named "CommandButton1_Click()" but thi
will be changed later.

I can use the code:

ActiveSheet.Shapes("CommandButton1").Visible = False

to hide the button if all cells are not completed, but I would prefe
to still see it but have it dis-enabled as if in the contro
properties. If I try to record a macro to disenable the button, th
only code that is recorded is the selection of the button.
Is there a way that this can be written in code? And where would
place the code, would it be in the Worksheet Selection_Change area?

Thanks For Any Help You Can Give.


Celtic_Avenger
:confused: :confused: :confused: :confused: :confused
 
N

Norman Jones

Hi Celtic_Avenger,

Try something like:

Private Sub CommandButton1_Click()
Dim rng As Range
Set rng = Range("E6, E8,E10,E12")
If Application.CountA(rng) < 4 Then
MsgBox "All four questions need to be answered", _
vbInformation
Else
'\\ optionally hide the button
'Me.CommandButton1.Visible = False
'\\ or disable the button
'Me.CommandButton1.Enabled = False

'Your continue code
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top