Vai al contenuto principale

Come applicare il gradiente di colore su più celle?

In Excel, possiamo facilmente riempire il colore di sfondo di una cella o più celle, ma, a volte, abbiamo bisogno che il colore sia riempito con gradiente come mostrato nella seguente schermata, come è possibile ottenere il gradiente di colore in una cella o su più celle in Excel?

Gradiente di colore su una cella Gradiente di colore su più celle
gradiente di colore doc 1 gradiente di colore doc 2

Applica il colore del gradiente a una cella con la funzione Formato celle

Applica il colore sfumato su più celle con codice VBA


freccia blu freccia destra Applica il colore del gradiente a una cella con la funzione Formato celle

In Excel, la funzione Formato celle può aiutarti a riempire il gradiente di colore in una cella, per favore fai come segue:

1. Seleziona una cella o più celle che desideri riempire con sfumatura di colore in ogni cella, quindi fai clic con il pulsante destro del mouse per scegliere formato celle dal menu contestuale, in formato celle finestra di dialogo, sotto il file Riempire scheda, fare clic Effetti di riempimento pulsante, vedi screenshot:

gradiente di colore doc 3

2. Nel Effetti di riempimento finestra di dialogo, selezionare due colori che si desidera utilizzare dai due elenchi a discesa di Colori sezione, quindi seleziona uno stile di ombreggiatura come preferisci, ad esempio orizzontale, verticale e così via. Vedi screenshot:

gradiente di colore doc 4

3. Quindi fare clic OK > OK per chiudere le finestre di dialogo e il colore del gradiente viene riempito per ogni cella come mostrato nella seguente schermata:

gradiente di colore doc 5


freccia blu freccia destra Applica il colore sfumato su più celle con codice VBA

Il metodo sopra può aiutarci a colorare il gradiente all'interno di una singola cella, se è necessario ombreggiare il gradiente di colore su più celle, è necessario applicare un codice VBA per risolverlo.

1. Innanzitutto, riempi un colore di sfondo specifico in un intervallo di celle.

2. Tieni premuto il ALT + F11 chiavi per aprire il Microsoft Visual Basic, Applications Edition finestra.

3. Clic inserire > Modulie incolla il codice seguente nel file Moduli Finestra.

Codice VBA: applica il colore del gradiente su più celle:

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. Quindi premere F5 chiave per eseguire questo codice e viene visualizzata una finestra di messaggio per ricordarti di selezionare le celle colorate che desideri riempire con il colore del gradiente, vedi screenshot:

 

gradiente di colore doc 6

5. E poi clicca OK pulsante, il colore all'interno di più celle è stato visualizzato come colore sfumato, vedi screenshot:

 

gradiente di colore doc 7

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
Comments (24)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thanks for the awesome code.

How do I make the gradient go from colour to white top to bottom?
How would i choose between two colours?
This comment was minimized by the moderator on the site
Hello, Tra,
For the first question, to make the gradient go from color to white top to bottom, please apply the following 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


For the second question, to fill the gradient with two colors, please apply the belwo code:
Note: to change the two colors, you just need to change the RGB in the code.
Sub colorgradientmultiplecells()
    'Updateby Extendoffcie
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xColor1 As Long
    Dim xColor2 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
    xColor1 = RGB(255, 0, 0) ' Red color
    xColor2 = RGB(0, 0, 255) ' Blue color
    For K = 1 To xRg.Columns.Count
        For I = xCount To 1 Step -1
            xRg.Cells(I, K).Interior.Color = RGB( _
                Int((xCount - (I - 1)) / xCount * (xColor2 Mod 256) + (I - 1) / xCount * (xColor1 Mod 256)), _
                Int((xCount - (I - 1)) / xCount * ((xColor2 \ 256) Mod 256) + (I - 1) / xCount * ((xColor1 \ 256) Mod 256)), _
                Int((xCount - (I - 1)) / xCount * (xColor2 \ 65536) + (I - 1) / xCount * (xColor1 \ 65536)))
        Next
    Next
    Application.ScreenUpdating = True
End Sub


Please have a try, hope them can help you!
This comment was minimized by the moderator on the site
Hallo,

Ich habe zu erst den ersten code verwendet, das funktioniert aber leider nicht. der färbt nur einzelne Zellen und die in komplett anderen Farben. Der Code für dunkel oben nach hell unten funktioniert gar nicht bei mir. Da kommt immer ein Syntax Error. Gibt es noch andere möglichkeiten einen Farbverlauf über mehrere Zellen zu erschaffen oder gibt es da eine andere Lösung für mich?

Vielen lieben Dank vorab schon mal.
This comment was minimized by the moderator on the site
Hello, How can I aply this formula for two colors, above I can't watch de solution. Please
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
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!
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
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!
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
Why I got Black-White color replace my gradient
This comment was minimized by the moderator on the site
Hello! I have the same problem, i choose the colors for my gradient but when applying the code it turns into black to white gradient. Anyy help?? thanks!
This comment was minimized by the moderator on the site
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!
This comment was minimized by the moderator on the site
hey, I'm not that used to VBA codes. How do I set another color in the code?
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
thanks! it works :)
This comment was minimized by the moderator on the site
How do I get this to have the gradient go left to right?
This comment was minimized by the moderator on the site
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!
This comment was minimized by the moderator on the site
How can I make the code to go it from right to left, Thanks in advance
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
Is it possible to perform this gradient but from bottom left to top right?
This comment was minimized by the moderator on the site
Is it possible to post a code that does gradient from top to bottom? I would really appreciate it.
This comment was minimized by the moderator on the site
I would need the code from the darkest shade at the top to the lighter shade at the bottom as well.. :(
This comment was minimized by the moderator on the site
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!
This comment was minimized by the moderator on the site
How would I do this if I wanted it top left to bottom right gradient?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations