+ Reply to Thread
Results 1 to 3 of 3

VBA Set Color Text Variable based on color entry in a cell?

  1. #1
    Registered User
    Join Date
    01-15-2018
    Location
    East Coast
    MS-Off Ver
    Office 365
    Posts
    55

    VBA Set Color Text Variable based on color entry in a cell?

    Hello, I keep getting errors when trying to set the text color based on a variable. I am sure I am doing something wrong that is fairly simple.

    I have a cell that contains the text "vbRed" or "RGB(255,0,0)". I have the following code:

    Please Login or Register  to view this content.
    The getadminvarvalue gets the data from the cell it finds (again text is entered "vbRed" or "RGB(255,0,0)"), so that parts works correctly. Now the problem occurs when I try to apply the following code:

    Please Login or Register  to view this content.
    If I use the following code it works, but I cannot figure out how to get it work using a variable.

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    both work.

    I appreciate your help and insight!

  2. #2
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: VBA Set Color Text Variable based on color entry in a cell?

    I believe the problem is arising from you trying to set the color to a string variable - the color must be set to either an RGB value (a long type variable), or a vbconstant (e.g. vbred).
    The easiest way to get around this would be to change the type of cuTextColor to long, and do something like this
    Please Login or Register  to view this content.
    Or in your case, if you want to set the variable based on the text in a cell, you could use
    Please Login or Register  to view this content.
    Except this uses cell "A1" and you would need to change that to your target cell

  3. #3
    Registered User
    Join Date
    01-15-2018
    Location
    East Coast
    MS-Off Ver
    Office 365
    Posts
    55

    Re: VBA Set Color Text Variable based on color entry in a cell?

    Thanks. I will give it a try and let you know how it goes!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Change cell format (cell color+font color) based on color of another cell
    By Dedaluss in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2017, 03:27 AM
  2. [SOLVED] Changing color of Tabs based on cell entry
    By $mart Group in forum Excel General
    Replies: 2
    Last Post: 03-11-2017, 04:51 PM
  3. Replies: 8
    Last Post: 03-08-2015, 10:02 AM
  4. Macro to change cell text color based on darkness of cell fill color
    By cincyshirm61 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-25-2014, 12:11 PM
  5. Replies: 4
    Last Post: 12-29-2013, 11:41 PM
  6. [SOLVED] Row Color based on cell entry
    By briank in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-21-2006, 01:25 PM
  7. change text color based on adjacent cell text color
    By matthewst in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-01-2005, 03:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1