MsgBox when Cell Selected

lucasb

New Member
Joined
Jun 9, 2010
Messages
8
I have a written a little piece of code that i cannot seem to get to work, basically when a range is selected (in this case D9) i want a message box to appear, vbyesno choices given and then a simple clear contents to follow, can some one help me with why this does not work?

As Always, thanks in advance

<code>Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = Range("D9").Address Then

MsgBox("Do You Want To Delete all Historical Data For This Person?", vbYesNo + vbQuestion)

If vbYes Then

Range("ManData").ClearContents

Else

Exit Sub

MsgBox "Please Enter New Name, All old Data Has Been Cleared"


End Sub<code>
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim x As VbMsgBoxResult
If Target.Address = Range("D9").Address Then
    x = MsgBox("Do You Want To Delete all Historical Data For This Person?", vbYesNo + vbQuestion)
    If x = vbYes Then
        Range("ManData").ClearContents
    Else
        Exit Sub
    End If
    MsgBox "Please Enter New Name, All old Data Has Been Cleared"
End If
End Sub
 
Upvote 0
[SOLVED]Re: MsgBox when Cell Selected

VoG,

Love your work, does exactly what i need.

Thanks over and over!
 
Upvote 0
You are welcome. It could be simplified

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("D9").Address Then
    If MsgBox("Do You Want To Delete all Historical Data For This Person?", vbYesNo + vbQuestion) = vbYes Then
        Range("ManData").ClearContents
        MsgBox "Please Enter New Name, All old Data Has Been Cleared", vbInformation
    End If
End If
End Sub
 
Upvote 0
Thanks again,

I was close, the shorter version allows me to see the couple of steps i took wron, always useful.

Cheers;)
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top