Message popup

G

Guest

Have a button on worksheet that clears certain cells on the sheet, would like
that a message box pops up when pressed asking user for confirmation, have
added below to the script on button but it clears cells regardless wether you
say O/k or cancel need reposne to O/k "clears cells" or cancel " does not
clear cells"
Dim response As Long
response = MsgBox(prompt:="ok or cancel", Buttons:=vbOKCancel)
'
Range("A2:A32,C2:C32,D2:D32,E2:E32,H2:H32").Select
Range("H2").Activate
Selection.ClearContents
Range("A2").Select
End Sub
 
B

Bryan Hessey

try extracting from:

Dim response
response = MsgBox(prompt:="ok or cancel", Buttons:=vbOKCancel)
If response < 2 Then
For i = 1 To Worksheets.Count + 3
Range("Q" & i + 10) = ""
Next
End If

that should help
 
G

Guest

This is what my script looks like now and it still deletes all data if cancel
is pushed
Dim response
response = MsgBox(prompt:="ok or cancel", Buttons:=vbOKCancel)
If response < 2 Then
For i = 1 To Worksheets.Count + 3
Range("Q" & i + 10) = ""
Next
End If

'
Range("A2:A32,C2:C32,D2:D32,E2:E32,H2:H32").Select
Range("H2").Activate
Selection.ClearContents
Range("A2").Select
End Sub
 
B

Bryan Hessey

Ahha, yes, my mistake, I should have been more clear, but I preferred t
show how it worked for me (with copy - paste) rather than type in her
as I type so badly.

You need

Dim response
response = MsgBox(prompt:="ok or cancel", Buttons:=vbOKCancel)
If response < 2 Then
Range("A2:A32,C2:C32,D2:D32,E2:E32,H2:H32").Select
Range("H2").Activate
Selection.ClearContents
Range("A2").Select
End if
End Sub


This is what my script looks like now and it still deletes all data i
cancel
is pushed
Dim response
response = MsgBox(prompt:="ok or cancel", Buttons:=vbOKCancel)
If response < 2 Then
For i = 1 To Worksheets.Count + 3
Range("Q" & i + 10) = ""
Next
End If

'
Range("A2:A32,C2:C32,D2:D32,E2:E32,H2:H32").Select
Range("H2").Activate
Selection.ClearContents
Range("A2").Select
End Sub
 
B

Bob Phillips

Dim response
response = MsgBox(prompt:="ok or cancel", Buttons:=vbOKCancel)
If response < vbOK Then
For i = 1 To Worksheets.Count + 3
Range("Q" & i + 10) = ""
Next
'
Range("A2:A32,C2:C32,D2:D32,E2:E32,H2:H32").ClearContents
Range("A2").Select
End If

End Sub

Is that what you want?

--

HTH

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

Bryan Hessey

NO Bob, he does not need the code
For i = 1 To Worksheets.Count + 3
Range("Q" & i + 10) = ""
Next
'
as that was a part of how I used the OK/Cancel.

My post (timed 54 minutes before your reply) explained this,

bbc1 needs

Dim response
response = MsgBox(prompt:="ok or cancel", Buttons:=vbOKCancel)
If response < 2 Then
Range("A2:A32,C2:C32,D2:D32,E2:E32,H2:H32").Select
Range("H2").Activate
Selection.ClearContents
Range("A2").Select
End if
End Sub
 
E

Earl Kiosterud

If MsgBox(prompt:="Do you REALLY wanna do this?", Buttons:=vbYesNo) = vbYes
Then
' code goes here
End If
 
G

Guest

That works great
Thankyou.

Bryan Hessey said:
Ahha, yes, my mistake, I should have been more clear, but I preferred to
show how it worked for me (with copy - paste) rather than type in here
as I type so badly.

You need

Dim response
response = MsgBox(prompt:="ok or cancel", Buttons:=vbOKCancel)
If response < 2 Then
Range("A2:A32,C2:C32,D2:D32,E2:E32,H2:H32").Select
Range("H2").Activate
Selection.ClearContents
Range("A2").Select
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