Free Microsoft Excel 2013 Quick Reference

Run Macro When Select Cell

Hi All,

I know you can run a macro when a new variable is entered in a cell, but can
you run a macro when a cell is selected?



Post your answer or comment

comments powered by Disqus
The guide to "Excel VBA: Automatically Run Excel Macros When a Cell Changes/Enter Data. Worksheet Change Event" was helpful in getting me started, but I couldn't do what I wanted. Here is what I want: When I type in data to a cell and press enter, I want a previously created macro to run.

Hi !

I use Excel a lot but don't understand VBA much.

I have looked at a series of Change Event topics and code but can't see what I need.

I simply want a macro to run automatically when a cell ....which contains the Maximum time from a range.... changes.

I assume I use .... Private Sub Worksheet_Change(ByVal Target As Excel.Range) ...but I have no idea what code to use...

can anyone help ??



I have a macro that I would like to execute when a change is made to a particular cell. The code I have right now runs the macro constantly on my page. I would like it to run only when a change is made to the relevant cell. The code I have on in my worksheet is as follows:

Public Sub Worksheet_SelectionChange(ByVal Target As Range) 
    Application.ScreenUpdating = False 
    Call HideHumidityArrows(Shapes) 
    Application.ScreenUpdating = True 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
The macro hides some boxes that I have displayed on the page, its code is as follows:

    If Range("G13").Value = "NO" Then 
        Shapes("DRH_Arrow").Visible = False 
        Shapes("ToH_Arrow").Visible = False 
        Shapes("EH_Arrow").Visible = False 
        Shapes("DRH_Arrow").Visible = True 
        Shapes("ToH_Arrow").Visible = True 
        Shapes("EH_Arrow").Visible = True 
    End If 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
Any help on getting this macro to run only when the cell G13 is changed would be greatly appreciated.


Hi all,

Need a little 'best method' help with a phonecall log,
where ColumnA is Date, ColumnB is Time.
I wanna be able to click on B2 and have the current time inserted, then
click on B3 and have another time inserted w/o changing B2.

I've know this has been discussed before, but Im still confused if a
macro is needed in this simple case.
Can an event trigger be worked into a formula function or must it be
In a previous thread it was suggested to Insert/Name/Define a cell
range with a macro or function name. Will this then trigger a macro to
(ctrl + shift +or (=3DNow),
or do I need to use something more like the excerpt below;

( "Mike Fogleman Mar 18, 4:00 am show options

Newsgroups: microsoft.public.excel.programming
From: "Mike Fogleman" <> - Find messages by
this author
Date: Fri, 18 Mar 2005 07:00:57 -0500
Local: Fri,Mar 18 2005 4:00 am
Subject: Re: Run Macro When Select Cell
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

Private Sub Worksheet_SelectionChange(ByVa=ADl Target As Range)
If Not Application.Intersect(Range("J=AD1:J100"), Target) Is Nothing
'Call your Macro
End If
End Sub

Change the Intersect Range to whatever cell or range you want as the
This code goes in the Worksheet Module, not a general module.

Mike F ")



I've seen plenty of code for running a macro when various events occur, but how do I run a macro when a cell is simply selected? I have a calendar Macro, and there are two cells that need date input. I want the user to select the cell, and the calendar to pop up. Macro for the calendar works correctly, just need the code for the activation upon cell selection. Thanks.

Hi - I think is a pretty simple question for a number of you, but does anyone know how to write code to run a macro when a cell is selected?

I've been trawling the net for days looking for this one, and have come close, but can't seem to make anything work.

Grateful for your help!

Hi guys!

Is it possible to run a macro when a cell is clicked (with the mouse arrow) but NOT when is selected with, say, the keyboard?

i.e I want to run a macro when A2 is clicked but not when I change my active cell with the keyboard arrows.



How do you run a macro when the selection moves to the next row?

For example, a user enters data in several cells on a row. When he hits 'ENTER' or selects a cell on the next row, a Macro would be run.

Thanks in advance.

Hi all,

I'm hoping someone can help get me out of a pickle before by brain melts.

I am using the following macro in my worksheet -

ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

I am trying to figure out how to launch this macro, when a cell is updated. (If this is possible)

Basically, I have a stats spreadsheet for tracking work, and need to capture the time a piece of work is completed.

Column B will record this by using this formula-


Then, when cell A1 is updated with a 'Y' to indicate the work is complete, the current time is recorded in B1. Then by running the macro, the time is fixed and will not change (as the NOW() function will continually update).

If I can get the macro to run when A1 is updated, my problem is solved.

I have considered using a checkbox or button to run the macro. There are a couple of problems with this. Firstly, as the worksheet may contain thousands of rows it is time consuming to duplicate the object in each row. Secondly, when the object is selected/clicked - there is no guarantee that A1 will be the activecell - meaning the macro will not do it's intended job.

Could also use shapes - which can be linked to the corresponding cell to work around this potential problem. However, same issue - with thousands of rows - I will have to update each shapes cell link.

Any help would be greatfully accepted!!!!



I am trying to run a macro when cells are changing in a sheet.
The macro shall take a cell value from the active sheet and search for this value in a specific column in another sheet.
The code goes like this:
Private Sub Worksheet_Change(ByVal Target As Range)
    anstnr = Selection.Value
    rad = Selection.Row
    temp_anstnr = Selection.Value
    Do While temp_anstnr <> anstnr
        Cells(rad, 1).Select
        temp_anstnr = Selection.Value
        rad = rad + 1
End Sub
This code stops at
. Why?
When I run a macro with the same code manuelly it is working fine!

Hoping for help,

I am trying to construct a macro that is available when a sheet is opened to identify when a particular cell is reached (or value of another cell changes). Then run a message box to ask the user if they wish to record the information they have just entered. Currently the code executes when the sheet is opened as well as when the cell is reached, I only want the message box to appear if a particular cell is active.

    If Intersect(Range("h10"), Target) Is Nothing Then Exit Sub 
    If Application.WorksheetFunction.IsText(Target.Value) Then 
        If Target.Address = "h10" And Target.Value = "Y" Then "MyMacro" 
    End If 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines

How can I have a macro run when any cell in Range("MyRange") is changed?



I'm new to this. It might be easy for some of you but how can I detect that the user pasted values in a certain range of cell?
I want to run a macro when these cell received some new pasted values. For Range(F105:I110)

Thanks for the hint!

I'd like to run a macro when a cell value changes conditionally, based on values entered into precedent cells (so that I'm not actually selecting or typing into the cell in focus) - is this possible? Ideally, I'd like to have a message box pop up, but could also insert a comment or autoshape. I can't find a way to get VBA to recognize such a change.
Thank you for your help!

Hello All,

I am trying to write a Macro that will automatically select a range of cells. The macro I am using is as follows:

    Sheets("Pivot Table").Select
    ActiveCell.Offset(1, 0).Select
    Range(Selection, Selection.End(xlToRight)).Offset(0, -1).Select
In my particular worksheet the value "Period" is on cell C3. So the Macro should select cells C4:T4. However when I run the Macro it actuall selects cells B4:T4

Does anybody know what the mistake in this code is?

Hey Dears,

I have excel 2003 file for Time card for several employees.
In this I have to run a macro when a cell value change, whatever the value is. < or >.

I have below macro to run when a cell value changes.
For example when i enter any value in A5, at the same time D5 is also change, and macro runs.
But during this macro execution D5 is changes again itself and this macro runs again and it is repeating the macro whenever D5 changes.

But I need macro to run only one time when D5 changes, not to repeat.
Please can anyone help me in this regard.
Thanks in advance.


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
  Range("CurrRec").Value = Range("AL38").Value
    If Sheets("Input").Range("AR3").Value <> olval Then
        End If
  Exit Sub
       olval = Sheets("Input").Range("AR3").Value
End Sub

I have a command button to run a macro and it works great except in one condition. If I start to edit a cell, then click the button, the macro does not run. If I end the edit of the cell by clicking Enter or clicking on another cell, then click the button, the macro does run. How can I get the button to take the focus, end the other edit, and run the macro when I click it while in the middle of editing a cell?

I wish to create a macro which would activate a text box on event. I have a range with 12 months. Under this range I created 12 text boxes with comments for each month (one on top of another). Click on a month range should bring forward a text box with comments for a respective month.

I recorded a simple macro which brings a text box forward. How can I assign it to an event (run macro when month cell is selected)?

Sub SelectJune()

ActiveSheet.Shapes.Range(Array("Text Box 2", "Line 10")).Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes.Range(Array("Line 6", "Line 7", "Line 9")).Select
Selection.ShapeRange.ZOrder msoSendToBack
End Sub

I attach a file with example. Thank you in advance!

Thanks for reading this post.
I want to run a macro when user switches to excel file from other applications.
I dont want to run macro when user swithces between open excel files.

Perhaps terribly simple... how does one tell Excel/VBA to run a particular macro when a particular cell is selected?

Worksheet_SelectionChange works for when a user leaves a cell, but...?

Thanks in advance for any help...

HI I am new to this board. I have been looking for an answer to this question for a while. I found the post by PNeely on 04/21/2003 and thought I had it figured out, but I cannot get the code to run. Here is what I have...


Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Address "$b$10" Then Exit Sub
End Sub

I also replaced the ComboBox11.Activate in this statement with a macro, and when I run the macro by it's self it works. But when I select cell b10 on the worksheet it does not trigger the macro.

Any help would be greatly appreciated.


How would you run a macro when cell a12 is selected or clicked? Or when the range a12:I15 is selected?


I have been trying to figure this out for hours now.

I just want to run a macro when a certain cell is selected.
upon investigation, i have found that I can right click on the sheet tab and
view the code. I can then add the following code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$a$1" Then
end if
End Sub

I know that this doesn't work, but I can't figure out how to get it to work.
Any help will be greatly appreciated.

thanks in advance


G'day groovers,

I am trying without success to for a macro to run when a specific cell is activated. i.e.

if a users selects cell A1, macro X will run.

Any assistance will be appreciated.



No luck finding an answer? You could always try Google.