Vba selection change

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,266
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi,

How can i fire a macro on a sheet when a cell is changed?
in my case each time cell b5 is change i need to fire this macro.
Thank you
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Put this in a module for the sheet. Right-click the sheet tab, choose 'View Code' and copy/paste the code below into the white space.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, [B1]) Is Nothing Then
    MsgBox "Cell B1 was changed" ' here you can call the macro you want to fire 
End If
End Sub
 
Upvote 0
Thank u
why did we need the target.count > 1?
cheers
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B5")) Is Nothing Then
    "Your Code
End If
End Sub
 
Upvote 0
Thank u
why did we need the target.count > 1?
cheers
Suppose a range like A5:C5 is selected and the change is made to A5 only, then do you want the macro to fire? I assumed not so limited the change to a single cell which has to be B5.
 
Upvote 0

Forum statistics

Threads
1,203,353
Messages
6,054,916
Members
444,759
Latest member
TeckTeck

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