Note: The other languages of the website are Google-translated. Back to English
Vpiši se  \/ 
x
or
x
Registracija  \/ 
x

or

Kako uporabiti barvni gradient v več celicah?

V Excelu lahko enostavno zapolnimo barvo ozadja v celico ali več celic, včasih pa moramo barvo zapolniti z gradientom, kot je prikazano na spodnji sliki zaslona, ​​kako lahko dobimo barvni gradient v celici ali v več celicah v Excelu?

Preliv barve na eno celico Preliv barv v več celicah
gradient doc barve 1 gradient doc barve 2

Uporabite gradient barvo na eno celico s funkcijo Format Cells

Uporabite barvo preliva v več celicah s kodo VBA


puščica modri desni mehurček Uporabite gradient barvo na eno celico s funkcijo Format Cells

V Excelu vam funkcija Format Cells pomaga pri zapolnitvi barvnega gradienta v eni celici, naredite naslednje:

1. Izberite celico ali več celic, ki jih želite zapolniti z barvnim gradientom vsake celice, in nato z desno miškino tipko izberite Oblikuj celice iz kontekstnega menija v Oblikuj celice v pogovornem oknu pod Izpolnite kliknite zavihek Učinki polnjenja gumb, glej posnetek zaslona:

gradient doc barve 3

2. v Učinki polnjenja v dveh pogovornih oknih izberite dve barvi, ki jih želite uporabiti Barve in nato izberite želene sloge senčenja, na primer vodoravno, navpično itd. Oglejte si posnetek zaslona:

gradient doc barve 4

3. Nato kliknite OK > OK , da zaprete pogovorna okna, za vsako celico pa je napolnjena barva preliva, kot je prikazano na sliki spodaj:

gradient doc barve 5


puščica modri desni mehurček Uporabite barvo preliva v več celicah s kodo VBA

Zgornja metoda nam lahko pomaga pri barvnem prelivu znotraj posamezne celice, če želite zasenčiti barvni preliv v več celicah, morate za njegovo rešitev uporabiti kodo VBA.

1. Najprej v vrsto celic napolnite določeno barvo ozadja.

2. Držite tipko ALT + F11 tipke za odpiranje Microsoft Visual Basic za aplikacije okno.

3. Kliknite Vstavi > Moduliin prilepite naslednjo kodo v Moduli Okno.

Koda VBA: Uporabi prelivno barvo v več celicah:

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. Nato pritisnite F5 tipko za zagon te kode in pojavilo se bo pozivno polje, ki vas bo opozorilo na izbiro barvnih celic, ki jih želite zapolniti z gradientom, glejte sliko zaslona:

 

gradient doc barve 6

5. In nato kliknite OK gumb, barva v več celicah je prikazana kot prelivna barva, glejte posnetek zaslona:

 

gradient doc barve 7


Najboljša orodja za pisarniško produktivnost

Kutools za Excel rešuje večino vaših težav in poveča produktivnost za 80%

  • Ponovna uporaba: Hitro vstavite zapletene formule, grafikoni in vse, kar ste že uporabljali; Šifriraj celice z geslom; Ustvari poštni seznam in pošiljanje e-pošte ...
  • Vrstica Super Formula (enostavno urejanje več vrstic besedila in formule); Bralna postavitev (enostavno branje in urejanje velikega števila celic); Prilepite v filtrirani obseg...
  • Združi celice / vrstice / stolpce brez izgube podatkov; Vsebina razdeljenih celic; Združi podvojene vrstice / stolpce... prepreči podvojene celice; Primerjaj obsege...
  • Izberite Duplicate ali Unique Vrstice; Izberite prazne vrstice (vse celice so prazne); Super Find in Fuzzy Find v mnogih delovnih zvezkih; Naključna izbira ...
  • Natančna kopija Več celic brez spreminjanja sklica formule; Samodejno ustvarjanje referenc na več listov; Vstavi oznake, Potrditvena polja in še več ...
  • Izvleček besedila, Dodaj besedilo, Odstrani po položaju, Odstrani presledek; Ustvari in natisni vmesne seštevke strani Pretvarjanje med vsebino celic in komentarji...
  • Super filter (shranite in uporabite sheme filtrov za druge liste); Napredno razvrščanje glede na mesec / teden / dan, pogostost in drugo; Poseben filter s krepko, ležeče ...
  • Združite delovne zvezke in delovne liste; Spoji tabele na podlagi ključnih stolpcev; Razdelite podatke na več listov; Paketna pretvorba xls, xlsx in PDF...
  • Več kot 300 zmogljivih funkcij. Podpira Office / Excel 2007-2019 in 365. Podpira vse jezike. Preprosta namestitev v vašem podjetju ali organizaciji. Vse funkcije 30-dnevnega brezplačnega preskusa. 60-dnevno jamstvo za vračilo denarja.
zavihek kte 201905

Kartica Office prinaša vmesnik z zavihki v Office in poenostavi vaše delo

  • Omogočite urejanje in branje z zavihki v Wordu, Excelu, PowerPointu, Publisher, Access, Visio in Project.
  • Odprite in ustvarite več dokumentov v novih zavihkih istega okna in ne v novih oknih.
  • Poveča vašo produktivnost za 50% in vsak dan zmanjša na stotine klikov z miško!
dno pisarniške mize
Say something here...
symbols left.
You are guest
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.
    MArcela CAmargo · 5 months ago
    Hello, How can I aply this formula for two colors, above I can't watch de solution. Please

  • To post as a guest, your comment is unpublished.
    Gordon · 8 months 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 · 2 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 · 2 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.
        Gord Thompson · 7 months 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.
    Piyaphan · 2 years ago
    Why I got Black-White color replace my gradient
    • To post as a guest, your comment is unpublished.
      Nicolas · 6 months ago
      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!
    • To post as a guest, your comment is unpublished.
      skyyang · 2 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 · 3 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 · 3 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 · 3 years ago
        thanks! it works :)
  • To post as a guest, your comment is unpublished.
    Sean · 3 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 · 3 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 · 1 years 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 · 1 years 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 · 1 years 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 · 3 years ago
        How would I do this if I wanted it top left to bottom right gradient?