+ Reply to Thread
Results 1 to 2 of 2

VBA Code Conditional Formatting based on number range

  1. #1
    Registered User
    Join Date
    08-05-2011
    Location
    Irving, Texas
    MS-Off Ver
    Excel 2003
    Posts
    1

    VBA Code Conditional Formatting based on number range

    I need help getting this code to work. I have 1 cell (s25) that I need the conditional formatting in the code to be applied to based on the number in the cell. For example if the number is 6,003 then the cell turns blue, if the number is 25,005 then the cell turns tan, etc...).

    I am not receiving any error messages on the code but nothing is happening in the cell whenever a change is made? Could someone please help me?
    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim icolor As Integer

    If Not Intersect(Target, Range("S25")) Is Nothing Then
    Select Case Target

    Case 1 To 6000

    icolor = 35

    Case 6001 To 25000

    icolor = 37

    Case 25001 To 50000

    icolor = 40

    Case 50001 To 75000

    icolor = 4

    Case 75001 To 100000

    icolor = 6

    Case 100001 To 400000

    icolor = 3

    End Select

    Target.Interior.ColorIndex = icolor

    End If

    End Sub

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA Code Conditional Formatting based on number range

    First off you need to put code tags around your code, otherwise you'll get wrong.

    Secondly, the code you have works fine for me, so the issue is probably where the code is - are you sure it's in the sheet that you're changing and not some other sheet?

+ 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