Activate Msgbox when cell A1:A3 is selected

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm trying to create a VBA code whereby if cells A1:A3 are selected in a worksheet a Msgbox will produce a message.

For example, when in selecting cells A1:A3 Msgbox will produce "Selected".

If you can help, please provide a code because I'm stuck.

Thank you!

Pinaceous
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I'm trying to create a VBA code whereby if cells A1:A3 are selected in a worksheet a Msgbox will produce a message.

For example, when in selecting cells A1:A3 Msgbox will produce "Selected".
Right click the tab at the bottom of the worksheet that you want to have this functionality and select "View Code" from the popup menu that appears, then copy/paste this code in the code window that opened up...
Code:
[table="width: 500"]
[tr]
	[td]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Not Intersect(Target, Range("A1:A3")) Is Nothing Then MsgBox "Selected"
End Sub[/td]
[/tr]
[/table]
That's it... now go back to the worksheet and try it out.
 
Last edited:
Upvote 0
Copy/paste this macro in the code module for your worksheet, not in a regular module:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Range("A1:A3")) Is Nothing Then Exit Sub
    MsgBox ("Selected")
End Sub
 
Upvote 0
You can also write this way.

Code:
Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        MsgBox "A1 was Selected"
    ElseIf Target.Address = "$A$2" Then
        MsgBox "A2 was Selected"
    ElseIf Target.Address = "$A$3" Then
        MsgBox "A3 was Selected"
    Else
        Exit Sub
    End If
End Sub
 
Last edited:
Upvote 0
A non-VBA approach would be to use Data Validation (with the condition =TRUE) with an input message of your choosing.
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,549
Members
449,170
Latest member
Gkiller

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