How to apply color gradient across multiple cells?

In Excel, we can easily fill background color to a cell or multiple cells, but, sometimes, we need the color be filled gradient as following screenshot shown, how could get the color gradient in a cell or across multiple cells in Excel?

Color gradient to one cell Color gradient across to multiple cells
doc color gradient 1 doc color gradient 2

Apply gradient color to one cell with Format Cells feature

Apply gradient color across multiple cells with VBA code


arrow blue right bubble Apply gradient color to one cell with Format Cells feature

In Excel, the Format Cells feature can help you to fill the color gradient in one cell, please do as follows:

1. Select a cell or multiple cells that you want to be filled with color gradient each cell, and then right click to choose Format Cells from the context menu, in the Format Cells dialog box, under the Fill tab, please click Fill Effects button, see screenshot:

doc color gradient 3

2. In the Fill Effects dialog, select two colors that you want to use from the two drop down lists of Colors section, and then select one shading styles as you like, such as horizontal, Vertical, and so on. See screenshot:

doc color gradient 4

3. Then click OK > OK to close the dialogs, and the gradient color is filled for each cell as following screenshot shown:

doc color gradient 5


arrow blue right bubble Apply gradient color across multiple cells with VBA code

The above method can help us to color gradient within individual cell, if you need to shade the color gradient across multiple cells, you need apply a VBA code to solve it.

1. First, fill a specific background color to a range of cells.

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Apply gradient color across multiple cells:

Sub colorgradientmultiplecells()
'Updateby Extendoffcie 
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xColor As Long
    Dim I As Long
    Dim K As Long
    Dim xCount As Long
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
LInput:
    Set xRg = Application.InputBox("please select the cells range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    If xRg.Areas.Count > 1 Then
        MsgBox "does not support multiple selections", vbInformation, "Kutools for Excel"
        GoTo LInput
    End If
    On Error Resume Next
    Application.ScreenUpdating = False
    xCount = xRg.Rows.Count
    For K = 1 To xRg.Columns.Count
        xColor = xRg.Cells(1, K).Interior.Color
        For I = xCount To 1 Step -1
            xRg.Cells(I, K).Interior.Color = xColor
            xRg.Cells(I, K).Interior.TintAndShade = (xCount - (I - 1)) / xCount
        Next
    Next
End Sub

4. Then press F5 key to run this code, and a prompt box is appeared to remind you selecting the colored cells that you want to fill gradient color, see screenshot:

 

doc color gradient 6

5. And then click OK button, the color within multiple cells has displayed as gradient color, see screenshot:

 

doc color gradient 7


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Gordon · 6 days ago
    Hello, Can you apply this to a range like 1 to 5 , cells having a number in them, having the 5 as the darkest ?

    Would Kutools be able to do a little similar to above , but then arrange a row of numbers into a scale - not good at explaining. Say a survey answering on a scale of 1 to 5 , then graphical show one bar per question showing percent of answers in 1, 2 ,3 ,4 ,5 ; 5% 1's, 10% 2's 15% 3's and 50% 4's , 20% 5's but showing a gradient of colours in a horizontal bar (better if 2 colours).

    Thanks , Gord
  • To post as a guest, your comment is unpublished.
    Alan · 1 years ago
    Hi, I've tried copying the VBA code but when I try to run it I keep getting a message that says 'Compile Error: Invalid Outside Procedure'....


    How do I fix this??


    Thanks!
  • To post as a guest, your comment is unpublished.
    Jasmin · 1 years ago
    Hello, how can I go from yellow to red (for example)? It works only from White to an other color. I work with the code from left to right.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Jasmin,
      Sorry for that, this code only applied to one color, and if you want to fill gradient from left to tight, the below comment has the solution, please check it.
      Thank you!
  • To post as a guest, your comment is unpublished.
    Piyaphan · 2 years ago
    Why I got Black-White color replace my gradient
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Piyaphan,
      The above code works well in my worksheet, which Excel version do you use?
      Or you can give your problem more detailed.
      Thank you!
  • To post as a guest, your comment is unpublished.
    paul · 2 years ago
    hey, I'm not that used to VBA codes. How do I set another color in the code?
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hello, paul,
      If you want to set another color, you just need to fill your desired color to the cells, and then apply the above code in this article.
      Please try it.
      • To post as a guest, your comment is unpublished.
        paul · 2 years ago
        thanks! it works :)
  • To post as a guest, your comment is unpublished.
    Sean · 2 years ago
    How do I get this to have the gradient go left to right?
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hello, Sean,
      To apply the color gradient from left to right, please use the following VBA code:

      Sub colorgradientmultiplecells()
      Dim xRg As Range
      Dim xTxt As String
      Dim xCell As Range
      Dim xColor As Long
      Dim I As Long
      Dim K As Long
      Dim xCount As Long
      On Error Resume Next
      If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
      Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
      End If
      LInput:
      Set xRg = Application.InputBox("please select the cells range:", "Kutools for Excel", xTxt, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      If xRg.Areas.Count > 1 Then
      MsgBox "does not support multiple selections", vbInformation, "Kutools for Excel"
      GoTo LInput
      End If
      On Error Resume Next
      Application.ScreenUpdating = False
      xCount = xRg.Columns.Count
      For K = 1 To xRg.Rows.Count
      xColor = xRg.Cells(K, 1).Interior.Color
      For I = xCount To 1 Step -1
      xRg.Cells(K, I).Interior.Color = xColor
      xRg.Cells(K, I).Interior.TintAndShade = (xCount - (I - 1)) / xCount
      Next
      Next
      End Sub

      Hope it can help you, thank you!
      • To post as a guest, your comment is unpublished.
        Ashley · 2 years ago
        How can I make the code to go it from right to left, Thanks in advance
        • To post as a guest, your comment is unpublished.
          skyyang · 2 years ago
          Hello, Ashley,
          To make the color gradient from right to left, the following vba code can help you, please try it.

          Sub colorgradientmultiplecells()
          Dim xRg As Range
          Dim xTxt As String
          Dim xCell As Range
          Dim xColor As Long
          Dim I As Long
          Dim K As Long
          Dim xCount As Long
          On Error Resume Next
          If ActiveWindow.RangeSelection.Count > 1 Then
          xTxt = ActiveWindow.RangeSelection.AddressLocal
          Else
          xTxt = ActiveSheet.UsedRange.AddressLocal
          End If
          LInput:
          Set xRg = Application.InputBox("please select the cells range:", "Kutools for Excel", xTxt, , , , , 8)
          If xRg Is Nothing Then Exit Sub
          If xRg.Areas.Count > 1 Then
          MsgBox "does not support multiple selections", vbInformation, "Kutools for Excel"
          GoTo LInput
          End If
          On Error Resume Next
          Application.ScreenUpdating = False
          xCount = xRg.Columns.Count
          For K = 1 To xRg.Rows.Count
          xColor = xRg.Cells(K, 1).Interior.Color
          For I = xCount To 1 Step -1
          xRg.Cells(K, I).Interior.Color = xColor
          xRg.Cells(K, I).Interior.TintAndShade = I / xCount
          Next
          Next
          End Sub
          • To post as a guest, your comment is unpublished.
            Kristina · 6 months ago
            Is it possible to perform this gradient but from bottom left to top right?
      • To post as a guest, your comment is unpublished.
        Sean · 2 years ago
        Is it possible to post a code that does gradient from top to bottom? I would really appreciate it.
        • To post as a guest, your comment is unpublished.
          Laura · 5 months ago
          I would need the code from the darkest shade at the top to the lighter shade at the bottom as well.. :(
          • To post as a guest, your comment is unpublished.
            skyyang · 4 months ago
            Hi, Laura,
            To sove your task, please apply the folloiwng code:

            Sub colorgradientmultiplecells()
            'Updateby Extendoffcie
            Dim xRg As Range
            Dim xTxt As String
            Dim xCell As Range
            Dim xColor As Long
            Dim I As Long
            Dim K As Long
            Dim xCount As Long
            On Error Resume Next
            If ActiveWindow.RangeSelection.Count > 1 Then
            xTxt = ActiveWindow.RangeSelection.AddressLocal
            Else
            xTxt = ActiveSheet.UsedRange.AddressLocal
            End If
            LInput:
            Set xRg = Application.InputBox("please select the cells range:", "Kutools for Excel", xTxt, , , , , 8)
            If xRg Is Nothing Then Exit Sub
            If xRg.Areas.Count > 1 Then
            MsgBox "does not support multiple selections", vbInformation, "Kutools for Excel"
            GoTo LInput
            End If
            On Error Resume Next
            Application.ScreenUpdating = False
            xCount = xRg.Rows.Count
            For K = 1 To xRg.Columns.Count
            xColor = xRg.Cells(1, K).Interior.Color
            For I = xCount To 1 Step -1
            xRg.Cells(I, K).Interior.Color = xColor
            xRg.Cells(I, K).Interior.TintAndShade = I / xCount
            Next
            Next
            End Sub

            Please try, hope it can help you!
      • To post as a guest, your comment is unpublished.
        Daisy · 2 years ago
        How would I do this if I wanted it top left to bottom right gradient?