User Defined Function Stops Working When Renaming File

cluffj

New Member
Joined
Jul 11, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have an excel file that is exported weekly that I need to convert certain cell colors into other colors. To accomplish this I found a User Defined Function =identifycolor (seen below) that I wrote into the conditional formatting to change the color of a cell if it met one of the color codes. This worked beautifully until I tried to save a copy of the file and send it to a coworker. When I got into VBA in the new file the UDF is still there but all of my cell colors are wrong. How do I fix this?

VBA Code:
Function IdentifyColor(CellToTest As Range)

'Returns R + (256 * G) + (65536 * B)
'IdentifyColor = 255 for red, 65280 for green, etc.
IdentifyColor = CellToTest.Interior.Color

End Function

UDF working:
Formatting With UDF.png


UDF not working:
Original Format.png
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You'd have to clarify the CF rules, since your UDF doesn't do any colouring itself. Are you sure they enabled macros?
 
Upvote 0
Welcome to the Board!

In addition to what Rory asked, how exactly are you renaming the file?
Are you renaming it to an extension which allows VBA (i.e. "xlsm" or "xlsb")?
 
Upvote 0
You'd have to clarify the CF rules, since your UDF doesn't do any colouring itself. Are you sure they enabled macros?
Also adding @Joe4

Screenshot below of the Conditional Format rules. Also, this is saved as a .xlsm.

1657555455675.png


They are enabling macros, however I'm curious if I can copy the formatting and paint it to the new document to avoid them needing to do this step. The deliverable just needs to have the final colors and dates.
 
Upvote 0
Welcome to the Board!

In addition to what Rory asked, how exactly are you renaming the file?
Are you renaming it to an extension which allows VBA (i.e. "xlsm" or "xlsb")?

Right now I've just tried right clicking the file and copy/paste.
 
Upvote 0
Right now I've just tried right clicking the file and copy/paste.
So it appears that maybe you are copying/pasting ranges.
Why not just a file "SaveAs"?
That should make a complete copy of the entire workbook, formatting and VBA included.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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