Consulting

Results 1 to 9 of 9

Thread: Excel Cell Color

  1. #1

    Excel Cell Color

    Hi,

    I got to do a code change which involves reading the color of a cell in Excel and impose some condition if the cell color is "Yellow",

    Can any body please give me a rough idea on this, iam not really a VBA developer , i work as a cognos developer , but i was given this taks to do,

    So i don't know if it is really a simple or complex one,

    Hoping for some help

    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    If Range("A1").Interior.Colorindex = 6 Then
    'your code
    End If
    [/vba]
    Last edited by Bob Phillips; 01-10-2008 at 11:55 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Hi,
    Thank you so much for the quick reply, One more favor, can you please tell me what is "A1" and is color index "6" for every color?
    In my case i have to check for "Yellow",
    please excuse me as my questions are lil foolish as i don't have knowledge on this

    Thanks

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    A1 is the cell on the spreadsheet cell being checked, 6 is the colorindex for yellow.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    got it, Thank you

  6. #6
    Hi,
    Can you please tell me how to read a particular number from the content of a cell,
    For ex: if the cell value is "34256789 Sample 1", how can i read just the last digit("1")?
    My team lead told me to read the value from right until i hit the first space,
    Can you please help me with this?
    Thanks,

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With Range("A1")
    MsgBox Right(.Value, Len(.Value) - InStrRev(.Value, " "))
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    Thank you very much, Can you please tell me how can i assign this to a filed called "sample number"

    I mean is it like
    SampleNumber = "With Range("A1")
    MsgBox Right(.Value, Len(.Value) - InStrRev(.Value, " "))
    End With

    Can you please give me an idea?

    Thanks

  9. #9
    Hello There,
    The function to get the color of the cell didn't work for me
    It is giving the error like "Error is 1004 Method 'Range' of object '_Global' failed"
    Can you please help me with this?

    Thanks,

Posting Permissions

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