HELP PLEASE Any one Know how

L

Lars-Åke Aspelin

Please, anyone can tell me how can i run macro by selecting a cell?

TIA

WC

Try the following sub which you put into the worksheet where the cell
is:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not (Intersect(Target, Range("E5")) Is Nothing) Then
MsgBox "E5 was selected"
End If
End Sub

Hope this helps / Lars-Åke
 
F

franciz

assuming you want to select row 4 and col 20, use this

Cells(4, 20).Select

regards, xlsops
 
B

Bob Phillips

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$H$1" Then

Call MyMacro
End If
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.
 
W

Wile Coyote

@TK2MSFTNGP06.phx.gbl:

Many Thanks

Is possible for address to be any cell in a column

TIA

WC
 
D

Don Guillett

A bit of thought on your part would have yielded

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' If Target.Address = "$H$1" Then
If Target.column = 6 Then

Call MyMacro
End If
End Sub
 
W

Wile Coyote

@TK2MSFTNGP06.phx.gbl:
Thanks Don

i am at the point of knowing just enough to get an idea then getting
myself stuck in the middle of it.

i was thinking along the line of defining a range or that i had to define
"address" as a group of cells.

i am still struggling a bit with the hiearchy of the syntex.

i appreciate your help. It really is quite obvious, when one thinks in
the correct direction, as i clearly was not doing.

Thanks to all who replyed

WC
 
B

Bob Phillips

You can also use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target., Me.Range("B:B")) Is Nothing Then

Call MyMacro
End If
End Sub

or


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target., Me.Range("B2:B20")) Is Nothing Then

Call MyMacro
End If
End Sub
 
Top