+ Reply to Thread
Results 1 to 6 of 6

Conditional formatting of ForeColor in VBA

  1. #1
    Registered User
    Join Date
    07-30-2009
    Location
    Vancouver, British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    46

    Question Conditional formatting of ForeColor in VBA

    Hi,

    I need the ForeColor of a checkbox text on a userform to change colour depending on certain criteria. Here's the code I have:

    Please Login or Register  to view this content.
    The issue is that tbEffectiveDOT is reading from a cell, and the cell contains a formula (the formula being "=J28"). So no matter what it's always > 0.

    What I would like is, if tbEffectiveDOT is empty or equals a default value, the forecolor of cbBillExclusion stays black, but if not empty or doesn't equal the default value, then the forecolor should change to red.

    Any ideas?

    Cheers,

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Conditional formatting of ForeColor in VBA

    Why not directly reference the cell? E.g.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-30-2009
    Location
    Vancouver, British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Conditional formatting of ForeColor in VBA

    Quote Originally Posted by StephenR View Post
    Why not directly reference the cell? E.g.
    Please Login or Register  to view this content.
    Because the userform is just reading the column and activecell (this case it's on J28). When the user clicks "next" on the userform, it'll jump to "J29".

    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Conditional formatting of ForeColor in VBA

    OK, so replace the J28 with the textbox in what I outlined. Are you asking how to structure an If/Or statement?

  5. #5
    Registered User
    Join Date
    07-30-2009
    Location
    Vancouver, British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Conditional formatting of ForeColor in VBA

    Quote Originally Posted by StephenR View Post
    OK, so replace the J28 with the textbox in what I outlined. Are you asking how to structure an If/Or statement?
    Your outline has partially worked:

    Please Login or Register  to view this content.
    When I click "next" on the userform, cbBillExclusion turns red when tbPolicyNumber is empty, but then it stays red. If I keep clicking next and then there is something in tbPolicyNumber, cbBillExclusion stays red (but I need it to go back to black).

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Conditional formatting of ForeColor in VBA

    You were pretty much there with your first post. You forgot to add the Else bit, so incorporate the Or part into your Else line and you should be home and dry.

+ 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