click event on cell

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

click event on cell

Post by sal21 »

i almost forgot vba for excel...


i need to use a click event on cell and start MYMacro...

but only in this case:

1) i can click only a single cell in column B from row 8, to the end of last filled cell
2) the cell can have a value, not blank
3) when the cell is clicked retrive the number of row and assign to MyVar (As Long)

tks

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: click event on cell

Post by HansV »

Right-click the sheet tab.
Select 'View Code' from the context menu.
Copy the following code into the worksheet module:

Code: Select all

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column = 2 And Target.Row >= 8 And Target.Value <> "" Then
        MyVar = Target.Row
    End If
End Sub
(I assume that you have declared MyVar elsewhere)
Best wishes,
Hans