How return built-in constant value from its name

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,720
Cell A1 contains the string: rgbAliceBlue

rgbAliceBlue is a built-in VBA constant with the numeric value of 16775408

In the VBE Immediate window if I enter ?rgbAliceBlue it shows the value: 16775408

Application.Evaluate("rgbAliceBlue") returns Error 2029 - Type mismatch

How can I extract the numeric value of a built-in excel constant using the name of a built-in excel constant?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,244
Office Version
365
Platform
Windows
How about
Code:
val(rgbAliceBlue)
 

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,720
val(rgbAliceBlue) does return the numeric value, but when I retrieve the value of a text string in Range("A1") it is processed as a string and Val("rgbAliceBlue") returns 0

I want to retrieve the name of a color from A1

A1 = rgbAliceBlue

which is a text value

In code
x = Range("A1") .Value
or
x = Range("A1") .Value2
or
x = Range("A1") .Text

all result in x having the value of "rgbAliceBlue" (a string)

and Val(X) returns 0, not 16775408 (the value of the constant: rgbAliceBlue)

Is there a function (or code) that will return the numeric value of a built-in constant using its name as input?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,244
Office Version
365
Platform
Windows
I missed the part about it being in A1.
And have no idea how to convert a string to a constant
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,504
Office Version
2010
Platform
Windows
I am pretty sure you cannot retrieve the value directly as, to my understanding, all constants are replaced by their value at the time the code is compiled (which is before the code itself physically executes), so the running VB code has no knowledge that a constant name was used originally and, hence, does not know that rgbAliceBlue is the name of a constant nor that it has an associated value.
 

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,720
Thank you both for your suggestions and comments.

I had thought there might be some way to use the functionality of the immediate window since it returns numeric values when evaluating the built-in constants.
 
Last edited:

Forum statistics

Threads
1,082,065
Messages
5,362,976
Members
400,702
Latest member
oliviaalx

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top