Automatically starting macros

  • Thread starter Thread starter Shawn777
  • Start date Start date
S

Shawn777

Can I get a macro to start once a cell range is changed?

I want to validate fixed input to a cell which will provide a dropdown menu
of selections to pick from. My question is can I get a marco to run once a
new selection is entered into the cell.
 
Right click on the sheet tab you want to react to the change and select view
code. Fust above the code window are 2 drop down menus. Change the one on the
left from General to Worksheet (A code stub will be added which we can delete
later). the drop down on the right now lists all of the events that you can
catch in a worksheet. Select the Change event and a code stub like this will
be added...

Private Sub Worksheet_Change(ByVal Target As Range)

End Sub

Target is a refence to the cell/s that have been changed so something like
this will catch a specific cell...

Private Sub Worksheet_Change(ByVal Target As Range)
if target.address = "$A$1" then msgbox target.value
End Sub
 
Shawn777 said:
Thank you, it took a few trys but I got it to work.

I also wanted a macro to run automatically, but when a particular worksheet
is opened. The Worksheet - Activate selection worked fine. Each time I now
open the worksheet the marco automatically updates its data analysis from
another worksheet. Great !
 
Shawn777 said:
Can I get a macro to start once a cell range is changed?

I want to validate fixed input to a cell which will provide a dropdown menu
of selections to pick from. My question is can I get a marco to run once a
new selection is entered into the cell.

See the other answers about Worksheet Change. It also works if you want a
macro to run when the sheet is activated. Choose Worksheet - Activate and put
your code there. I have it to automatically update an analysis of data from
another sheet.
 
Back
Top