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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

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