hide/unhide command button

  • Thread starter Thread starter Pa Maher
  • Start date Start date
P

Pa Maher

I am developing a quiz template.
After the question is answered I want to display or activate a "Next
Question" command button (affording the test taker the opportunity to review
the answer and explanation of the answer before progressing to the next
question).
After the "Next Question" is presented, the "Next Question" command button
should be hidden or deactivated until the new question is answered correctly.
 
Add a commandbar from the Control Toolbox (NOT the Forms toolbar) and use change event code like
this

'In a regular module
Public CorrectAnswer As Variant

'You'll need code to assign the correct answer to CorrectAnswer

In the worksheet codemodule of your test sheet, use event code like

Private Sub Worksheet_Change(ByVal Target As Range)
'Answer is entered into cell D5
If Target.Address <> "$D$5" Then Exit Sub
If Target.Value = CorrectAnswer Then
Worksheets("Test Sheet").Shapes("CommandButton1").Visible = True
End If
End Sub


and when you change the question, use code like this to hide the button

Worksheets("Test Sheet").Shapes("CommandButton1").Visible = False


HTH,
Bernie
MS Excel MVP
 
Back
Top