Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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


Count and sum cells based on background color / font color / conditional formatting:
Kutools for Excel’s Count by Color can quickly count and sum cells based on background color, font color. With it, you can count and sum by conditional formatting color as well. Read more about this feature...
doc-filter-color-12

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 20160725
    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


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
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.
    Jasmin · 2 months 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 · 2 months 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 · 5 months ago
    Why I got Black-White color replace my gradient
    • To post as a guest, your comment is unpublished.
      skyyang · 4 months 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 · 1 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 · 1 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.
    Sean · 1 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 · 1 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 · 7 months 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 · 7 months 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.
        Sean · 8 months 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.
        Daisy · 1 years ago
        How would I do this if I wanted it top left to bottom right gradient?