Can't select macro button after other button is pressed

  • Thread starter Thread starter C. Campbell
  • Start date Start date
C

C. Campbell

I have a workbook with two sheets. There is a button on each sheet
with code to erase a named range without deleting areas that aren't
included in the range.

If I press a button, the code executes OK. Then when I go to the
other sheet I can't press the second button. Also, sometimes I can't
select it in design mode. Actually, I can select the button but when
I right-click it and select "Properties", it gives me the sheet
properties instead of the button properties.

What am I doing wrong?

Here is the button code:

Sub CommandButton1_Click()
'Erase data in Overtime Report sheet

vAnswer = msgbox("This will erase all your data but not the formulas.
Continue?", vbYesNo)

If vAnswer = vbYes Then
Application.Goto Reference:="OTDataEntry"
Selection.ClearContents
End If

Range("A1").Select
Range("E7").Select

End Sub
------------------------------------------
Sub CommandButton2_Click()
'Erase data in HOURS sheet

vAnswer = msgbox("This will erase all your data but not the formulas.
Continue?", vbYesNo)

If vAnswer = vbYes Then
Application.Goto Reference:="DataEntry"
Selection.ClearContents
End If

Range("A1").Select
Range("G3").Select

End Sub
 
If you want to get rid of these problems use a shape or a button from the
forms menu.

this might be a bit more efficient. NO selections and one line if

vAnswer = MsgBox("This will erase all your data but not the
formulas.Continue?", vbYesNo)
If vAnswer = vbYes Then Range("OTDataEntry").Clear
 

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

Back
Top