VBA Code to run when format is changed

magismo

New Member
Joined
Jan 21, 2012
Messages
1
Hi All,

I am trying to write a simple event code that will run when a format is changed. Essentially, when a cell format is changed to green I want to put a 1 in another cell.

Thanks in advance for your help
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
magisimo,

I am assuming that your cell will turn green or not, based on a conditional formatting rule.
The format change itself will not register as an event but the sheet change that satisfies the CF rule will.

So for example......
Your CF rule to set a cell or a range of cells green is =A5>20 and your cell to receive the value 1 is B1.

You could code something like .....

Code:
Private Sub Worksheet_Change (ByVal Target As Range)
Application.EnableEvents = False
If Range("A5").Value > 20 Then
Range("B1").Value = 1
Else
Range("B1").Value = ""  'Or Whatever
End If
Application.EnableEvents = True
End Sub

Hope that helps.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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