Run macro on cell selection

farmock2

New Member
Joined
Oct 29, 2014
Messages
23
When I run the following macro by selection of a cell within the range, the macro does not run until I select any other cell after selecting that cell. Is there any way to have the macro run immediately with selection of the cell in the range? Thanks for any help you can provide.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Intersect(Target, Range("C2:C100")) Is Nothing Then
      Exit Sub
   Else
      RunBTSlong
   End If
End Sub
 
Last edited by a moderator:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
with Worksheet_Change the target is the cell you are coming out of (triggers leaving the cell)
with Worksheet_SelectionChange the target is the cell you are going into (triggers entering the cell)
 
Last edited:
Upvote 0
Hello Farmock2,

You are using the wrong event procedure to run your macro. You need to use the Worksheet_SelectionChange event.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Intersect(Target, Range("C2:C100")) Is Nothing Then
      Exit Sub
   Else
      RunBTSlong
   End If
End Sub
 
Upvote 0
Your code will only run if you change the value of a cell in C2:C100, it will not run if you simply select a cell.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top