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

วิธีแบ่งรายการยาวเป็นกลุ่มเท่า ๆ กันใน Excel

doc แยกรายการเป็นกลุ่ม 4

หากคุณมีรายการข้อมูลจำนวนมากที่ต้องแบ่งออกเป็นกลุ่มเท่า ๆ กันหลายกลุ่มตามภาพหน้าจอต่อไปนี้คุณจะจัดการกับงานนี้อย่างรวดเร็วและง่ายดายใน Excel ได้อย่างไร?

แบ่งรายการยาวออกเป็นกลุ่มเท่า ๆ กันหลาย ๆ กลุ่มด้วยรหัส VBA

แบ่งรายการแบบยาวออกเป็นกลุ่มเท่า ๆ กันหลาย ๆ กลุ่มด้วย Kutools for Excel


ยกเว้นการคัดลอกและวางข้อมูลทีละรายการโค้ด VBA ต่อไปนี้สามารถช่วยคุณได้โปรดทำตามขั้นตอนต่อไปนี้:

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

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

รหัส VBA: แบ่งรายการยาว ๆ ออกเป็นกลุ่มเท่า ๆ กัน

Sub SplitIntoCellsPerColumn()
'updateby Extendoffice
    Dim xRg As Range
    Dim xOutRg As Range
    Dim xCell As Range
    Dim xTxt As String
    Dim xOutArr As Variant
    Dim I As Long, K As Long
    On Error Resume Next
    xTxt = ActiveWindow.RangeSelection.Address
Sel:
    Set xRg = Nothing
    Set xRg = Application.InputBox("please select data 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, please select again", vbInformation, "Kutools for Excel"
        GoTo Sel
    End If
    If xRg.Columns.Count > 1 Then
        MsgBox "does not support multiple columns,please select again", vbInformation, "Kutools for Excel"
        GoTo Sel
    End If
    Set xOutRg = Application.InputBox("please select a cell to put the result:", "Kutools for Excel", , , , , , 8)
    If xOutRg Is Nothing Then Exit Sub
    I = Application.InputBox("the number of cell per column:", "Kutools for Excel", , , , , , 1)
    If I < 1 Then
        MsgBox "incorrect enter", vbInformation, "Kutools for Excel"
        Exit Sub
    End If
    ReDim xOutArr(1 To I, 1 To Int(xRg.Rows.Count / I) + 1)
    For K = 0 To xRg.Rows.Count - 1
      xOutArr(1 + (K Mod I), 1 + Int(K / I)) = xRg.Cells(K + 1)
    Next
    xOutRg.Range("A1").Resize(I, UBound(xOutArr, 2)) = xOutArr
End Sub

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

doc แยกรายการเป็นกลุ่ม 1

4. และคลิก OK จากนั้นเลือกเซลล์ที่คุณต้องการค้นหาผลลัพธ์ในกล่องพร้อมต์ต่อไปนี้ดูภาพหน้าจอ:

doc แยกรายการเป็นกลุ่ม 2

5. คลิก OKและโปรดป้อนจำนวนเซลล์ที่คุณต้องการแยกต่อคอลัมน์ในกล่องพร้อมต์ดูภาพหน้าจอ:

doc แยกรายการเป็นกลุ่ม 3

6. สุดท้ายคลิก OK เพื่อสิ้นสุดรหัสและข้อมูลรายการที่เลือกถูกแบ่งออกเป็นกลุ่มเท่า ๆ กันหลายกลุ่มตามที่คุณต้องการดูภาพหน้าจอ:

doc แยกรายการเป็นกลุ่ม 4


ถ้าคุณได้ติดตั้ง Kutools สำหรับ Excelเดียวกันกับที่ ช่วงการแปลง คุณลักษณะนี้คุณสามารถแบ่งรายการยาว ๆ ออกเป็นหลายคอลัมน์และแถวได้อย่างรวดเร็วนอกจากนี้คุณยังสามารถรวมหลายคอลัมน์เป็นรายการเดียวได้อีกด้วย

Kutools สำหรับ Excel : ด้วย Add-in ของ Excel ที่มีประโยชน์มากกว่า 300 รายการทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน. 

หลังจากการติดตั้ง Kutools สำหรับ Excelโปรดดำเนินการดังนี้:

1. เลือกรายการแบบยาวที่คุณต้องการแยกจากนั้นคลิก Kutools > พิสัย > ช่วงการแปลงดูภาพหน้าจอ:

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

doc แยกรายการเป็นกลุ่ม 7

3. จากนั้นคลิก Okและเลือกเซลล์ที่คุณต้องการค้นหาผลลัพธ์ในกล่องพร้อมต์ดูภาพหน้าจอ:

doc แยกรายการเป็นกลุ่ม 8

4. และคลิก OK ข้อมูลในรายการจะถูกแบ่งออกเป็นหลายกลุ่มเท่า ๆ กันตามที่คุณต้องการ

ดาวน์โหลดและทดลองใช้ Kutools for Excel ฟรีทันที!


Kutools สำหรับ Excel: ด้วย Add-in ของ Excel ที่มีประโยชน์มากกว่า 300 รายการให้ทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน ดาวน์โหลดและทดลองใช้ฟรีทันที!

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

🤖 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 (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
the code works great for me. How do I change it from asking how many in each colum to how many columns needed? so that it equally divides the information into a set number of columns.
This comment was minimized by the moderator on the site
Hello, trinetta,
May be the following article can help you, in that article, there are some formulas may meet your need. Please check it:
https://www.extendoffice.com/documents/excel/681-excel-change-columns-to-rows.html
This comment was minimized by the moderator on the site
The link only tells me how to do the same thing. It doesnt tell me how to tell the code or formula how many columns i need...just how many in each column.
This comment was minimized by the moderator on the site
Hi, Tpdixon,
In that article, the formula: =OFFSET($A$1,COLUMNS($A1:A1)-1+(ROWS($1:1)-1)*5 can help you to split the list into mulitiple columns, you just need to change the number 5 to other number you need, it represents the column number.
After entering this formula, you should drag the fill handle acrross to right with 5 cells.
Please try, thank you!
This comment was minimized by the moderator on the site
how can I change it from the number of cells per column to the number of columns needed. so that the data is split up evenly amongst a number of columns instead of picking how many to have in each column?
This comment was minimized by the moderator on the site
I copied the code and Excel 365 says syntax error.
This comment was minimized by the moderator on the site
This comes in very handy! One question: In the VBA code how can I transpose the output? So instead of xRg.Rows.Count / I = number of colums output, the output is generated as xRg.Rows.Count / I = number of rows output with I being the number of columns per row.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations