Delete with command button?

  • Thread starter Thread starter John
  • Start date Start date
J

John

I have command button for deleting values in some cells, but it doesn't
work. Can someone help? Thanks !!

Private Sub cmdDelete_Click()
Dim a As Boolean

a = MsgBox("Do you want to delete?", vbYesNo)
Select Case a
Case a = vbYes

Worksheets(1).Range("C4:C13,E28:G32,E34:G36,E38:G48,E50:G57").Select
Selection.ClearContents
Case a = vbNo
ActiveSheet.Range("C4").Select
End Select
End Sub

Thanks!!
 
Dim a As Long
'...
Case vbYes
'...
Case vbNo
'...

HTH. Best wishes Harald
 
For some strange reason the VB developers did not make vbYes and vbNo
convertible directly to Boolean values. VBYes = 6 and vbNo = 7; converted to
Boolean they would both become True (i.e., non-zero). You need to Dim a as
an Integer variable.
 
Presumably because vbYes and VbNo are part of a much bigger enumeration, and
there are only two Boolean values.

You could always declare ans as vbMsgboxResult.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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