Workbook_BeforeClose question

iisailor

Board Regular
Joined
Feb 18, 2009
Messages
58
Hi everyone,
I currently have simple piece of code that changes the background colour of a cell to yellow whenever any changes take place in that cell.Perfect.
Now however i want any cells coloured yellow to change to the colour blue whenever the workbook is closed.
I know this should only be a a simple bit of code but its giving me great difficulty. Any help??
Thanks in advance
Chris
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this - change the sheet name to suit:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
For Each c In Sheets("Sheet2").UsedRange
    If c.Interior.ColorIndex = 6 Then c.Interior.ColorIndex = 5
Next c
End Sub
 
Upvote 0
This is to anybody but perhaps VoG you might know better along the line of questioning. The code in your reply does work perfect but is it possible to change it to select all the sheets in the workbook?? Ive tried several tweaks but to no avail.
Thanks again everyone
Chris
 
Upvote 0
Try this

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim c As Range, ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    For Each c In ws.UsedRange
        If c.Interior.ColorIndex = 6 Then c.Interior.ColorIndex = 5
    Next c
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,927
Members
448,533
Latest member
thietbibeboiwasaco

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