run a marco automatically

  • Thread starter Thread starter Dennis Cheung
  • Start date Start date
D

Dennis Cheung

i need a marco runs automatically after a selection in page area (i wonder
if it is called page area). is it possible? how to write the code?

example:
there are mutiple shops sales data in a pivot table. i want the marco to run
automatically after i select a different shop. since there are 2 tables in
one sheet. i need to merge 2 tables after selecting a different shop?

please help!

Dennis
 
thanks Carim! it all works. really appreciate for your kind assistance.
 
Hi Dennis,
The solution provided by Carim is appropriate for yor problem.
To run marco automatically after a selection:

Call the macro in "Worksheet_SelectionChange" event.

Here even you can restrict the macro call to particular range by
checking the Target parameter of event.

Regards.
 
Dear Vinit,

Since I am not familar to VBA. Can you explain more specific?
The selection is in range b2 and the marco name is marco1.

Dennis
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 2 and Target.Row= 2 Then 'For B2
ShowCellValue' macro1
End If
End Sub

Sub ShowCellValue() 'My Macro. macro1 in ur case
MsgBox "The value =" & ActiveCell.Value
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top