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

วิธีจัดเรียงหลายแถวหรือคอลัมน์อย่างอิสระพร้อมกันใน Excel

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

doc จัดเรียงหลายคอลัมน์ 1

จัดเรียงหลายคอลัมน์อย่างอิสระพร้อมกันด้วยรหัส VBA

จัดเรียงหลายแถวอย่างอิสระพร้อมกันด้วยรหัส VBA


ลูกศรสีฟ้าฟองขวา จัดเรียงหลายคอลัมน์อย่างอิสระพร้อมกันด้วยรหัส VBA

ในการจัดเรียงคอลัมน์หลายคอลัมน์อย่างเป็นอิสระจากน้อยไปหามากรหัส VBA ต่อไปนี้อาจช่วยคุณได้โปรดทำดังนี้

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

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

รหัส VBA: จัดเรียงหลายคอลัมน์อย่างอิสระพร้อมกัน:

Sub SortIndividualJR()
'Updateby Extendoffice
    Dim xRg As Range
    Dim yRg As Range
    Dim ws As Worksheet
    Set ws = ActiveSheet
    On Error Resume Next
    Set xRg = Application.InputBox(Prompt:="Range Selection:", _
                                    Title:="Kutools for excel", Type:=8)
    Application.ScreenUpdating = False
    For Each yRg In xRg
        With ws.Sort
            .SortFields.Clear
            .SortFields.Add Key:=yRg, Order:=xlAscending
            .SetRange ws.Range(yRg, yRg.End(xlDown))
            .Header = xlNo
            .MatchCase = False
            .Apply
        End With
    Next yRg
    Application.ScreenUpdating = True
End Sub

3. จากนั้นกด F5 คีย์เพื่อเรียกใช้รหัสนี้และกล่องพร้อมต์จะปรากฏขึ้นเพื่อเตือนให้คุณเลือกช่วงข้อมูลที่คุณต้องการจัดเรียงตามแต่ละคอลัมน์ดูภาพหน้าจอ:

doc จัดเรียงหลายคอลัมน์ 2

4. จากนั้นคลิก OKแต่ละคอลัมน์ได้รับการจัดเรียงตามลำดับในครั้งเดียวดูภาพหน้าจอ:

doc จัดเรียงหลายคอลัมน์ 1


ลูกศรสีฟ้าฟองขวา จัดเรียงหลายแถวอย่างอิสระพร้อมกันด้วยรหัส VBA

หากคุณต้องการจัดเรียงหลายแถวอย่างอิสระนี่คือรหัส VBA สำหรับคุณ

1. เลือกข้อมูลที่คุณต้องการจัดเรียงตามแต่ละแถว

doc จัดเรียงหลายคอลัมน์ 3

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

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

รหัส VBA: เรียงหลายแถวแยกกันพร้อมกัน:

Sub SortIndividualR()
'Updateby Extendoffice
    Dim xRg As Range, yRg As Range
    If TypeName(Selection) <> "Range" Then Exit Sub
    Set xRg = Selection
    If xRg.Count = 1 Then
        MsgBox "Select multiple cells!", vbExclamation, "Kutools for Excel"
        Exit Sub
    End If
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
    Application.ScreenUpdating = False
    For Each yRg In xRg.Rows
        yRg.Sort Key1:=yRg.Cells(1, 1), _
        Order1:=xlAscending, _
        Header:=xlNo, _
        Orientation:=xlSortRows
    Next yRg
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
    End With
    Application.ScreenUpdating = True
End Sub

4. จากนั้นกด F5 คีย์ในการเรียกใช้รหัสนี้ข้อมูลในแต่ละแถวได้รับการจัดเรียงพร้อมกันดูภาพหน้าจอ:

doc จัดเรียงหลายคอลัมน์ 4

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

🤖 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 (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
My data ranges from 0-100; When I Try to sort multiples rows at once, it starts the data off with the 100s, then sorts the rest numerically least to greatest, putting the 100s at the least side of the range. How can I fix this?
This comment was minimized by the moderator on the site
Update; I've realized it is sorting by the first digit in the number only - How do I get it to sort by the whole number?
This comment was minimized by the moderator on the site
Hi, Devyn,
The code works well in my worksheet. Could you upload your Excel file or data screenshot here? So that, we can help to check where the problem is?
Thank you!
This comment was minimized by the moderator on the site
Спасибо тебе человек!!
This comment was minimized by the moderator on the site
excellent post, thank you very much!
This comment was minimized by the moderator on the site
You have just saved me several headaches with this solution! Thanks a ton!
This comment was minimized by the moderator on the site
Thank you so much for this. It really helped. I would also like to know how to sort by color. I have 26 columns, each having different types of items identified by the font color. I would like to alphabetize all the columns individually but in a specific color order. How do I do this?
This comment was minimized by the moderator on the site
I love this, I'm curious as to the functionality of sorting by color for each column individually. I tried this but it didn't work:


Dim xRg As Range
Dim yRg As Range
Dim ws As Worksheet
Set ws = ActiveSheet
On Error Resume Next
Set xRg = Application.InputBox(Prompt:="Range Selection:", _
Title:="Kutools for excel", Type:=8)
Application.ScreenUpdating = False
For Each yRg In xRg
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=yRg, _
SortOn:=xlSortOnCellColor, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange ws.Range(yRg, yRg.End(xlDown))
.Header = xlNo
.MatchCase = False
.Apply
End With
Next yRg
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
¿Cómo puedo ordenar por color múltiples filas de forma independiente y que las celdas que no tengan color estén a la derecha?
This comment was minimized by the moderator on the site
When I try to sort the columns it sorts data outside of the sected range! Why is this?
This comment was minimized by the moderator on the site
It works great ! thank you !
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations