+ Reply to Thread
Results 1 to 20 of 20

Color formatting using VBA

  1. #1
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Lightbulb Color formatting using VBA

    IdealTasks.xlsm

    Hello,
    I'm trying to say --> If the cell color is blank Then say "I'm free". --> If the cell color is not blank Then say "I'm busy".

    In the cell N4 for example, the cell at the end of the row, it needs to say either "I'm free" or "I'm busy." My range is from B4 to L484.

    For example for the first row, B4 to L4, there is a red slot, so in N4 it needs to say "I'm busy" in the cell.

    Please Login or Register  to view this content.
    Last edited by rmachbitz; 07-01-2013 at 04:29 PM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Color formatting using VBA

    May be

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    AB33,

    I clarified my question above. Your code runs an infinite loop.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Color formatting using VBA

    For Each cel In Range("B4:L484")
    is finite loop.
    You must be referring to your own code

  5. #5
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    I ran your code. It pops up the MsgBox "I'm busy" as an infinite loop. Did you read the code I posted in Post #1?

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Color formatting using VBA

    I do not know what do you mean by infinite loop?

    Range("B4:L484"). There is lower(B4) and upper boundary(L484).
    Or do you want to exit the loops soon as you get the message?

  7. #7
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    The MsgBox "I'm busy" will not go away, this is what I mean by infinite loop. I want to exit the loop as soon as I get the message, yes!!

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Color formatting using VBA

    I am not sure which one is yes, but you can move out Exit For below MsgBox ("I'm busy")
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    Ok that works better, but what I'm trying to do is put the message in cell. For example, the cell N4 at the end of the row, it needs to say either "I'm free" or "I'm busy." In this case, the cell N4 would say I'm busy.

    My range is from B4 to L484. For example for the first row, B4 to L4, there is a red slot, so in N4 it needs to say "I'm busy" in the cell.

  10. #10
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Cool Re: Color formatting using VBA

    IdealTasks.xlsm

    Ideally this is how it should look for all the rows (see attached). I want to automate this process by looking at the colors in each row.

  11. #11
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    Please Login or Register  to view this content.
    It gives me the error "Object or variable not set"??

  12. #12
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    Please Login or Register  to view this content.
    RGB(255, 255, 255) is the color for white

  13. #13
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    Please Login or Register  to view this content.
    Object required error??

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Color formatting using VBA

    I don't know what the second If is doing, why all the concatenation?, but the error is because you are using cell.

    cell was the loop variable in the earlier code and can't be used in later code.
    If posting code please use code tags, see here.

  15. #15
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    If I declare the variable, do I declare it as a Range?
    Please Login or Register  to view this content.
    I'm using concatenation because I need all the cells from B to L to be white cells, in order for the N cell to say "I'm free".

    Please Login or Register  to view this content.

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Color formatting using VBA

    Concatenation joins the values in the cells together into one long string.

    You can't use it to check the interior colour of a group of cells.

    To do that you'll need to loop and check each cell.

  17. #17
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    Could you provide an example of what that loop structure would look like?

  18. #18
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    Please Login or Register  to view this content.
    The error is telling me there is no Else statement for my If statement. Is the code out of order??

  19. #19
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Color formatting using VBA

    Try this.
    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    06-20-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    106

    Re: Color formatting using VBA

    That works perfectly!!!!! Thanks This has been solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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