ไปยังเนื้อหาหลัก

จะใช้การไล่ระดับสีในหลายเซลล์ได้อย่างไร?

ใน Excel เราสามารถเติมสีพื้นหลังให้กับเซลล์หรือหลาย ๆ เซลล์ได้อย่างง่ายดาย แต่บางครั้งเราจำเป็นต้องเติมสีไล่ระดับตามภาพหน้าจอต่อไปนี้จะทำให้การไล่ระดับสีในเซลล์หรือในหลายเซลล์ใน Excel ได้อย่างไร

ไล่ระดับสีไปยังเซลล์เดียว ไล่ระดับสีไปยังหลายเซลล์
การไล่ระดับสี doc 1 การไล่ระดับสี doc 2

ใช้สีไล่ระดับกับเซลล์เดียวด้วยคุณสมบัติ Format Cells

ใช้สีไล่ระดับในหลายเซลล์ด้วยรหัส VBA


ลูกศรสีฟ้าฟองขวา ใช้สีไล่ระดับกับเซลล์เดียวด้วยคุณสมบัติ Format Cells

ใน Excel คุณลักษณะ Format Cells สามารถช่วยคุณเติมการไล่ระดับสีในเซลล์เดียวได้โปรดทำดังนี้:

1. เลือกเซลล์หรือหลายเซลล์ที่คุณต้องการเติมด้วยการไล่ระดับสีแต่ละเซลล์จากนั้นคลิกขวาเพื่อเลือก จัดรูปแบบเซลล์ จากเมนูบริบทในไฟล์ จัดรูปแบบเซลล์ ภายใต้ ใส่ โปรดคลิก เติมเอฟเฟกต์ ปุ่มดูภาพหน้าจอ:

การไล่ระดับสี doc 3

2. ใน เติมเอฟเฟกต์ ให้เลือกสองสีที่คุณต้องการใช้จากรายการดรอปดาวน์สองรายการ สี จากนั้นเลือกรูปแบบการแรเงาตามที่คุณต้องการเช่นแนวนอนแนวตั้งและอื่น ๆ ดูภาพหน้าจอ:

การไล่ระดับสี doc 4

3. จากนั้นคลิก OK > OK เพื่อปิดกล่องโต้ตอบและเติมสีไล่ระดับสำหรับแต่ละเซลล์ตามภาพหน้าจอต่อไปนี้:

การไล่ระดับสี doc 5


ลูกศรสีฟ้าฟองขวา ใช้สีไล่ระดับในหลายเซลล์ด้วยรหัส VBA

วิธีการข้างต้นสามารถช่วยเราในการไล่ระดับสีภายในเซลล์แต่ละเซลล์หากคุณต้องการแรเงาไล่ระดับสีในหลายเซลล์คุณต้องใช้รหัส VBA เพื่อแก้ปัญหา

1. ขั้นแรกให้เติมสีพื้นหลังที่ต้องการลงในช่วงของเซลล์

2. กด ALT + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

3. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในไฟล์ โมดูล หน้าต่าง.

รหัส VBA: ใช้สีไล่ระดับในหลายเซลล์:

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. จากนั้นกด F5 คีย์เพื่อเรียกใช้รหัสนี้และกล่องพร้อมต์จะปรากฏขึ้นเพื่อเตือนให้คุณเลือกเซลล์สีที่คุณต้องการเติมสีไล่ระดับดูภาพหน้าจอ:

 

การไล่ระดับสี doc 6

5. จากนั้นคลิก OK ปุ่มสีภายในหลายเซลล์แสดงเป็นสีไล่ระดับดูภาพหน้าจอ:

 

การไล่ระดับสี doc 7

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
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