+ Reply to Thread
Results 1 to 2 of 2

VBA Conditional Formatting with Gradient Fill

  1. #1
    Registered User
    Join Date
    02-25-2013
    Location
    England
    MS-Off Ver
    2010
    Posts
    27

    VBA Conditional Formatting with Gradient Fill

    Hi I'm trying to combine two sets of VBA but as I have very little expeience of dealing with VBA I don't know how. Basically I want to end up with what I described in the title.

    The First thing I'm wanting is to fill the cells background based on its Value, and based on what i've found online I have this example:

    If A1 contains "Emily", A2 contains "Joshua", A3 contains "Steve", and B1 to B3 contain values between 200 and 500 I have the following code:


    Private Sub Worksheet_Change(ByVal Target As Range)

    Set I = Intersect(Target, Range("B2:F11"))
    If Not I Is Nothing Then
    Select Case Target
    Case "Emily": Newcolor = 37
    Case "Joshua": Newcolor = 46
    Case "Steve": Newcolor = 12
    Case 200 To 300: Newcolor = 10
    Case 301 To 400: Newcolor = 3
    Case 401 To 500: Newcolor = 25
    End Select
    Target.Interior.ColorIndex = Newcolor
    End If

    But I also want the fill to be gradient with up to 3 colours and also be able to change the text colour rather than just having the basic one colour formatting of the previous example, more something utilizing the following perhaps?

    Set objColorStop = Sheet6.Cells.Interior.Gradient.ColorStops.Add(0)
    objColorStop.Color = RGB(0, 64, 255)

    Set objColorStop = Sheet6.Cells.Interior.Gradient.ColorStops.Add(0.33)
    objColorStop.Color = RGB(200, 64, 0)

    Set objColorStop = Sheet6.Cells.Interior.Gradient.ColorStops.Add(0.66)
    objColorStop.Color = RGB(128, 250, 0).

    But I have no idea what to edit in or out or how to construct a refined code, Any help in putting this together would be really appreciated!

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,401

    Re: VBA Conditional Formatting with Gradient Fill

    If you can provide a sample spreadsheet, it would help a lot. However, it doesn't appear that VB would be required to do this. I think it can be accomplished by conditional formatting.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Gradient fill across multiple cells
    By dforte in forum Excel General
    Replies: 2
    Last Post: 01-18-2016, 01:20 AM
  2. Gradient Fill Problem - Doughnut Chart
    By dgibney in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-24-2014, 07:07 AM
  3. Replies: 1
    Last Post: 07-22-2014, 03:01 AM
  4. [SOLVED] Gradient fill according to percentage
    By nooredein in forum Excel General
    Replies: 14
    Last Post: 04-28-2014, 02:14 PM
  5. Bar Graph specifying Gradient fill colors
    By coreytroy in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 03-18-2013, 08:39 PM
  6. Gradient Filling in Conditional Formatting
    By Tommy1005 in forum Excel General
    Replies: 0
    Last Post: 02-21-2011, 11:43 AM
  7. Custom Function for Fill Gradient?
    By rvExcelNewTip in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-03-2007, 08:58 AM

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