VBA msgbox if cells clicked in certain order

surkdidat

Well-known Member
Joined
Oct 1, 2011
Messages
582
Office Version
  1. 365
I need a bit of code if the user clicks on certin cells in order.

For example, if the user clicks on cell A1 then cell B1 and then cell C1 (in that order) - can a message box be displayed please?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
One way w/o using arrays:

In the Sheet Module:
VBA Code:
Option Explicit

Private oPrevRange As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With [B1]
        If Union(Target, [A1:C1]).Address <> [A1:C1].Address Then
            .ID = ""
        End If
        If Target.Address = [C1].Address Then
            If .ID = [A1].Address Then
                MsgBox "Hello"
            End If
        End If
        If Target.Address = .Address Then
            .ID = oPrevRange.Address
        End If
    End With
    Set oPrevRange = Target
End Sub

Note that the code will also fire when selecting the cells in that order using the keyboard keys. To limit this to mouse clicking , you will need a bit more code.
 
Upvote 1
Solution

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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