Message box to confirm action

G

Guest

I have the following code so that when a cell is selected, it copies all the
cells/formulas from the template worksheet to the active worksheet and
“overwrite†the target cells.

Now, how can I insert a “Pop Up Message†to ask “Are you sure?†and proceed
if Yes, exit if No?

(I just want to make sure if the cell is clicked by accident then the active
worksheet data is not lost.)

------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$K$1" Then
ActiveSheet.Unprotect
ActiveSheet.Range("N3:Q242").Formula =
Sheets("ProgramSummaryTemplate").Range("N3:Q242").Formula
ActiveSheet.Protect
Range("N3").Select
End If

Cancel = True
End Sub
------------------------
 
J

Jake Marx

Hi CRayF,

Something like this would do it:

If MsgBox("Are you sure?", vbYesNo Or vbQuestion _
Or vbDefaultButton2) = vbYes Then
'/ Your Code Here
End If

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]
 
B

Bob Phillips

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ans
If Target.Address = "$K$1" Then
Ans = Msgbox("Are tyou sure", vbYesNo")
If Ans = vbYes Then
ActiveSheet.Unprotect
ActiveSheet.Range("N3:Q242").Formula =
Sheets("ProgramSummaryTemplate").Range("N3:Q242").Formula
ActiveSheet.Protect
Range("N3").Select
End If
End If

Cancel = True
End Sub
 
A

Andrew

|I have the following code so that when a cell is selected, it copies all
the
| cells/formulas from the template worksheet to the active worksheet and
| â?ooverwriteâ? the target cells.
|
| Now, how can I insert a â?oPop Up Messageâ? to ask â?oAre you sure?â?
and proceed
| if Yes, exit if No?
|
| (I just want to make sure if the cell is clicked by accident then the
active
| worksheet data is not lost.)
|
Try this..!

| Private Sub Worksheet_SelectionChange(ByVal Target As Range)

| If Target.Address = "$K$1" Then

If MsgBox("Are you sure?", vbYesNo) = vbYes Then
| ActiveSheet.Unprotect
| ActiveSheet.Range("N3:Q242").Formula =
| Sheets("ProgramSummaryTemplate").Range("N3:Q242").Formula
| ActiveSheet.Protect
| Range("N3").Select
| End If
End If
| End Sub

HTH
Andrew
 
G

Guest

Perfect! Thanks

Jake Marx said:
Hi CRayF,

Something like this would do it:

If MsgBox("Are you sure?", vbYesNo Or vbQuestion _
Or vbDefaultButton2) = vbYes Then
'/ Your Code Here
End If

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

I have the following code so that when a cell is selected, it copies
all the cells/formulas from the template worksheet to the active
worksheet and "overwrite" the target cells.

Now, how can I insert a "Pop Up Message" to ask "Are you sure?" and
proceed if Yes, exit if No?

(I just want to make sure if the cell is clicked by accident then the
active worksheet data is not lost.)

------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$K$1" Then
ActiveSheet.Unprotect
ActiveSheet.Range("N3:Q242").Formula =
Sheets("ProgramSummaryTemplate").Range("N3:Q242").Formula
ActiveSheet.Protect
Range("N3").Select
End If

Cancel = True
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