Run Macro on Change in Worksheet

B

Bill

Hello,
I would like to run a macro when a change is made in a given column on a
worksheet (such as column B). I know I need to use:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

end sub

Not sure how this works though.

Thanks for your help.

Bill
 
B

Bob Phillips

Bill,

First test if the column is selected
If Target.Column = 2 Then

and then call your macro
myMacro

end the If statement
EndIf

The only other thing to say is that this code goes in the sheet module of
the sheet in question (right-click on the sheet tab, select View Code from
the menu, and put the code in there. Your macro should be in a normal code
module, and be a public 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

Top