ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can't select macro button after other button is pressed (https://www.excelbanter.com/excel-programming/318047-cant-select-macro-button-after-other-button-pressed.html)

C. Campbell

Can't select macro button after other button is pressed
 
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

Don Guillett[_4_]

Can't select macro button after other button is pressed
 
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

--
Don Guillett
SalesAid Software

"C. Campbell" wrote in message
m...
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





All times are GMT +1. The time now is 08:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com