+ Reply to Thread
Results 1 to 3 of 3

VBA Conditional formatting

  1. #1
    Registered User
    Join Date
    02-08-2010
    Location
    LOndon,England
    MS-Off Ver
    Excel 2003
    Posts
    2

    VBA Conditional formatting

    Hi all,

    I'm working on a spreadsheet that colours cells according to the cells value (as in conditional formatting). I've used VBA to forfill three of the four criteria necessary as follows.

    Private Sub Worksheet_Calculate()

    Set myrange = Range("c13:c32")


    Dim iColor As Integer
    Dim cell As Range


    For Each cell In myrange

    Select Case cell.Value

    Case Is < 85 'Red
    iColor = 3
    Case 85 To 90 'Amber
    iColor = 44
    Case Is > 90 'Green
    iColor = 10

    End Select


    cell.Interior.ColorIndex = iColor

    Next

    End Sub



    That was simple enough except I'd like one further colour, and the input comes from a different sheet in the same workbook (luckily with the same cell reference) The formatting criteria would be case <20 producing a cell colorindex of 20. Would it be possible to modify the vba script to accomodate this fourth conditional format.

    Kind regards,

    Moony

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Conditional formatting problem

    Hi MoonyShine, welcome to the forum. Be sure to read through the Forum Rules you agreed to already so you can use and follow them effectively. For instance, you'll need to edit that post above and put code tags around that code you used.

    Like this:
    Please Login or Register  to view this content.
    =======
    Also, what is the other sheet you want to test for this alternate value?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-08-2010
    Location
    LOndon,England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: VBA Conditional formatting

    Thanks JBeaucaire.

    Thank you for the advice.

    Please Login or Register  to view this content.
    The other sheet I'd like to test for this value is called ProviderTableTots


    Kind regards,

    Moony

+ 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