Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I am using this vba solution in an effort to trigger code when a cell is selected by a mouse click.
This works wonderfully if the cell is a single cell. In my scenario, I want the user's clickable area to be within a series of contigiuous cells (A1:H1).
This code does not work if the cells are merged. Fair enough.
I can accomplish the same visual effect by using the center across selection horizontal alignment (to define the range of cells the user can click). But, for the single click to work, the user has to select cell A1 exclsusivley. How can I adapt this code so that the user can trigger the code when any of the cells in that range (A1:H1) is clicked?
This works wonderfully if the cell is a single cell. In my scenario, I want the user's clickable area to be within a series of contigiuous cells (A1:H1).
This code does not work if the cells are merged. Fair enough.
I can accomplish the same visual effect by using the center across selection horizontal alignment (to define the range of cells the user can click). But, for the single click to work, the user has to select cell A1 exclsusivley. How can I adapt this code so that the user can trigger the code when any of the cells in that range (A1:H1) is clicked?
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Stop
Dim Message As MSG
'check for left-mouse button clicks.
PeekMessage Message, 0, 0, 0, PM_NOREMOVE
'if left-mouse clicked on cell A1 run macro
If Message.Message = 512 Then
If Selection.Address = Range("A1").Address Then
MsgBox "You clicked cell: " & Selection.Address
End If
End If
End Sub
Last edited: