+ Reply to Thread
Results 1 to 2 of 2

VBA code to check font color

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2007
    Posts
    12

    VBA code to check font color

    Checking the font color

    --------------------------------------------------------------------------------

    I want to write output based on font color

    Connected

    Connected
    Connected


    For the above , I want to see BLACK, RED and BLUE in the cells right of them

    I tried the following code:

    (created a module in the worksheet, saved it with Alt Q and it shows up in my user defined function list)

    Function Checkcolor(cell) As String
    If
    cell.fontcolor.ColorIndex = 1 Then
    Checkcolor = "BLACK"


    End Function

    Giving me a #value error - what I am doing wrong, will passing the parameter as a range help?

    Tia,

    XIX

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello ExcelInExcel,

    Yes, you need to declare the object type of the variable being passed as a Range.
    Function Checkcolor(cell As Range) As String
    
      If cell.fontcolor.ColorIndex = 1 Then Checkcolor = "BLACK"
    
    End Function
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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