ColorIn Function (1 Viewer)

Peter Quill

Member
Local time
Today, 18:05
Joined
Apr 13, 2023
Messages
30
Hello,

I just tried to utilize this function and it works great, The only problem is that if I change the color of a cell the function doesn't auto update. How can i get it to auto update?

I've created a worksheet where I'm using color to indicate if the cost of an item has been paid. If cell background color is yellow then it has not been paid if it isn't yellow then it has already been paid. My data is in a table and I'm using Excel 365
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:05
Joined
Feb 19, 2013
Messages
16,619
Never heard of a colorin function- please clarify. If it is a vba function then provide the code.

or perhaps you are referring to conditional formatting?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:05
Joined
Feb 28, 2001
Messages
27,194
Did a search, could NOT find the COLORIN function on three tries. The great Google brain keeps on saying "Did you mean "color in" (as two words). Did someone supply this function to you or perhaps did you find it in a forum somewhere? Or do you have an add-in package for Excel?
 

Peter Quill

Member
Local time
Today, 18:05
Joined
Apr 13, 2023
Messages
30
Hello,
Thanks all for your responses.
Once I created a function in the Name Manager that looks like this
=GET.CELL(63,INDIRECT("rc[-1]",FALSE)) this works but I don't know how it works but it does, it just doesn't update.
So I found this macro that looks like this:
Function ColorIn(color As Range) As Integer
ColorIn = color.Interior.ColorIndex
End Function

If there is a better way to achieve my goal I'm interested in hearing about it.
Thanks in advance.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:05
Joined
Oct 29, 2018
Messages
21,477
Just curious, have you tried using Conditional Formatting?
 

GPGeorge

Grover Park George
Local time
Today, 05:05
Joined
Nov 25, 2004
Messages
1,877
Yes, it was my first option. I am actually figuring out other options particularly this method to solve this issue.
I have a long-standing tradition. If there is a simple, effective, consistent, native way to accomplish a task, I use it and don't waste a lot of time trying to write a wad of new VBA code to replicate it. This applies not only to Access, but to Excel, PowerPoint, and Word, as well.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:05
Joined
Feb 28, 2001
Messages
27,194
Not only that, but if the input range is not single-celled, you only pick the upper left corner cell, even if the range is "rainbow."

When you say your function doesn't update, here is the question: When you tell Excel to do a full recompute, does it update then? Because if it does, you are simply not triggering anything to cause a recompute to occur. Excel doesn't ALWAYS recompute everything. Sometimes it is more selective.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:05
Joined
May 7, 2009
Messages
19,248
it could be easy as suggested in post#5.
can you post a sample xlsx/xlsm file with dummy data.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:05
Joined
Sep 21, 2011
Messages
14,319
Hello,
Thanks all for your responses.
Once I created a function in the Name Manager that looks like this
=GET.CELL(63,INDIRECT("rc[-1]",FALSE)) this works but I don't know how it works but it does, it just doesn't update.
So I found this macro that looks like this:
Function ColorIn(color As Range) As Integer
ColorIn = color.Interior.ColorIndex
End Function

If there is a better way to achieve my goal I'm interested in hearing about it.
Thanks in advance.
Nor do I :(
If anything I think all it would do is return the value of the fill colour?

I cannot even see where you call it. :(

Here is a line of code from a workbook of mine where I set it and fontcolor to a value stored in another sheet.

Code:
            .FormatConditions(wsCond.Cells(lngCounter, 8).Value).Font.Color = wsCond.Cells(lngCounter, 5).Value
            .FormatConditions(wsCond.Cells(lngCounter, 8).Value).Interior.Color = wsCond.Cells(lngCounter, 4).Value
 

Isaac

Lifelong Learner
Local time
Today, 05:05
Joined
Mar 14, 2017
Messages
8,779
A part of me wants to +1 to dbGuy's suggestion. If conditional formatting will work, then it will do a thousand times more for you with 1/1000th of the work of reinventing the wheel. Make sure you examine its capabilities vs. your need thoroughly before discarding.

On the other hand, I've had many experiences where I started out thinking C.F. would be fine. After a while things got more complex. Then files were copied, re-made, auto-generated, etc., and it got harder and harder to maintain the C.F. paradigm - super complex and in some cases hard to re-create (think hours of manual work).

If I had another need arise these days, I would still consider CF, but also strongly consider a VBA-based, infinitely scale-able option like maintaining a cross-reference (config) worksheet with Rules. Columns like Type (contains, equal to, not, less than, etc), Rank (once this is hit exit the rest), Colors (I like simplicity of rgb), etc. The VBA function would very quickly apply ALL of these rules, and re-apply them ALL on demand. Editing them would be relatively easy compared to maintaining (and passing around, and copying, and building upon) a complex set of rules in the CF dialogue window.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:05
Joined
Sep 21, 2011
Messages
14,319
Which is pretty much what I do now for a partciular sheet, although perhaps a little simpler.

However be warned, I am having problems with this where sometimes it does not put the correct row number in the formula when being applied.
I have walked though the code and the data is as per column C, yet Excel changes it to a very high number just short of the max row number or just a few rows away. :(

1687931668737.png
 

Isaac

Lifelong Learner
Local time
Today, 05:05
Joined
Mar 14, 2017
Messages
8,779
Which is pretty much what I do now for a partciular sheet, although perhaps a little simpler.

However be warned, I am having problems with this where sometimes it does not put the correct row number in the formula when being applied.
I have walked though the code and the data is as per column C, yet Excel changes it to a very high number just short of the max row number or just a few rows away. :(

View attachment 108574
That's very interesting, thanks for posting. Yes - something like that is exactly what I was imagining! And even better.

In your case I think you're probably using VBA to execute actual conditional formatting commands, right?
I was envisioning simply using VBA to set range colorindex interior etc. etc. etc.

I do like your way, a hybrid of homegrown + CF, but I have little to no experience with executing actual CF commands via VBA, so I can see where troubleshooting those CF formula-based rules could be tough. Your advantage is you're able to leverage Relativity without reinventing it explicitly all in code, which is nice, but also perhaps less documented for automation..

I can see how your way of doing it may tend to incur fairly complex layers of excel's "relative" brain-thinking ....... and possibly end up being hard to determine the reason.

What I was thinking of is a more literal, explicit applying of range colors ... which may avoid your occasional trouble-cases, but also likely be a bit slower.

It almost seems like perhaps you could test and switch to my more literal explicit method (no executing CF commands in VBA), without probably changing hardly anything about your config sheet.
 

Users who are viewing this thread

Top Bottom