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

วิธีสร้างแผ่นงานใหม่สำหรับแต่ละแถวใน Excel

สมมติว่าคุณมีตารางคะแนนที่มีชื่อนักเรียนทุกคนในคอลัมน์ A ตอนนี้คุณต้องการสร้างแผ่นงานใหม่ตามชื่อเหล่านี้ในคอลัมน์ A และทำให้แต่ละแผ่นมีข้อมูลของนักเรียนที่ไม่ซ้ำกัน หรือเพียงแค่สร้างแผ่นงานใหม่สำหรับแต่ละแถวในตารางโดยไม่ต้องคำนึงถึงชื่อในคอลัมน์ A ในวิดีโอนี้ คุณจะได้รับวิธีการต่างๆ

สร้างแผ่นงานใหม่สำหรับแต่ละแถวด้วยรหัส VBA
สร้างแผ่นงานใหม่สำหรับแต่ละแถวด้วยยูทิลิตี้ Split Data ของ Kutools for Excel


สร้างแผ่นงานใหม่สำหรับแต่ละแถวด้วยรหัส VBA

ด้วยรหัสต่อไปนี้คุณสามารถสร้างแผ่นงานใหม่ตามค่าคอลัมน์หรือสร้างแผ่นงานใหม่สำหรับแต่ละแถวใน Excel

1 กด อื่น ๆ + F11 พร้อมกันเพื่อเปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2 ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคลิก สิ่งที่ใส่เข้าไป > โมดูล. จากนั้นวางรหัสต่อไปนี้ลงในไฟล์ โมดูล หน้าต่าง

รหัส VBA: สร้างแผ่นงานใหม่สำหรับแต่ละแถวตามคอลัมน์

Sub parse_data()
'Update by Extendoffice 2018/3/2
    Dim xRCount As Long
    Dim xSht As Worksheet
    Dim xNSht As Worksheet
    Dim I As Long
    Dim xTRrow As Integer
    Dim xCol As New Collection
    Dim xTitle As String
    Dim xSUpdate As Boolean
    Set xSht = ActiveSheet
    On Error Resume Next
    xRCount = xSht.Cells(xSht.Rows.Count, 1).End(xlUp).Row
    xTitle = "A1:C1"
    xTRrow = xSht.Range(xTitle).Cells(1).Row
    For I = 2 To xRCount
        Call xCol.Add(xSht.Cells(I, 1).Text, xSht.Cells(I, 1).Text)
    Next
    xSUpdate = Application.ScreenUpdating
    Application.ScreenUpdating = False
    For I = 1 To xCol.Count
        Call xSht.Range(xTitle).AutoFilter(1, CStr(xCol.Item(I)))
        Set xNSht = Nothing
        Set xNSht = Worksheets(CStr(xCol.Item(I)))
        If xNSht Is Nothing Then
            Set xNSht = Worksheets.Add(, Sheets(Sheets.Count))
            xNSht.Name = CStr(xCol.Item(I))
        Else
            xNSht.Move , Sheets(Sheets.Count)
        End If
        xSht.Range("A" & xTRrow & ":A" & xRCount).EntireRow.Copy xNSht.Range("A1")
        xNSht.Columns.AutoFit
    Next
    xSht.AutoFilterMode = False
    xSht.Activate
    Application.ScreenUpdating = xSUpdate
End Sub

หมายเหตุ: A1: C1 คือช่วงหัวเรื่องของตารางของคุณ คุณสามารถเปลี่ยนแปลงได้ตามความต้องการของคุณ

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

หากคุณต้องการสร้างแผ่นงานใหม่สำหรับแต่ละแถวโดยตรงโดยไม่ต้องพิจารณาค่าคอลัมน์คุณสามารถใช้รหัสต่อไปนี้

รหัส VBA: สร้างแผ่นงานใหม่สำหรับแต่ละแถวโดยตรง

Sub RowToSheet()
	Dim xRow As Long
	Dim I As Long
	With ActiveSheet
		xRow = .Range("A" & Rows.Count).End(xlUp).Row
		For I = 1 To xRow
			Worksheets.Add(, Sheets(Sheets.Count)).Name = "Row " & I
			.Rows(I).Copy Sheets("Row " & I).Range("A1")
		Next I
	End With
End Sub

หลังจากรันโค้ดแล้วแต่ละแถวในแผ่นงานที่ใช้งานจะถูกวางไว้ในแผ่นงานใหม่

หมายเหตุ: แถวหัวเรื่องจะถูกวางไว้ในแผ่นงานใหม่ด้วยรหัส VBA นี้


สร้างแผ่นงานใหม่สำหรับแต่ละแถวด้วยยูทิลิตี้ Split Data ของ Kutools for Excel

อันที่จริงวิธีการข้างต้นซับซ้อนและเข้าใจยาก ในส่วนนี้เราจะแนะนำไฟล์ แยกข้อมูล ประโยชน์ของ Kutools สำหรับ Excel.

ก่อนที่จะใช้ Kutools สำหรับ Excelโปรด ดาวน์โหลดและติดตั้งในตอนแรก.

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

2 ใน แยกข้อมูลออกเป็นหลายแผ่นงาน โปรดทำดังนี้

A. สำหรับการสร้างแผ่นงานใหม่ตามค่าคอลัมน์:

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

B. สำหรับการสร้างแผ่นงานใหม่โดยตรงสำหรับแต่ละแถว:

1). เลือก แถวคงที่ ตัวเลือกป้อนหมายเลข 1 ลงในกล่อง;
2). เลือก หมายเลขแถว จาก กฎระเบียบ รายการแบบหล่นลง
3). คลิก OK ปุ่ม. ดูภาพหน้าจอ:

สมุดงานใหม่ถูกสร้างขึ้นโดยมีแผ่นงานใหม่ทั้งหมดอยู่ภายใน ดูภาพหน้าจอด้านล่าง

การสร้างแผ่นงานใหม่สำหรับแต่ละแถวตามค่าคอลัมน์:

การสร้างแผ่นงานใหม่สำหรับแต่ละแถวโดยไม่ต้องพิจารณาค่าคอลัมน์:

  หากคุณต้องการทดลองใช้ยูทิลิตีนี้ฟรี (30 วัน) กรุณาคลิกเพื่อดาวน์โหลดแล้วไปใช้การดำเนินการตามขั้นตอนข้างต้น

สร้างแผ่นงานใหม่สำหรับแต่ละแถวด้วยยูทิลิตี้ Split Data ของ Kutools for Excel

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

🤖 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 (33)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
HI, Thanks for this wonder-full code, Can we get dynamic sheet, means if i update data in respective sheet it will get updated in main sheet.
This comment was minimized by the moderator on the site
Hi vikas chandra,
I can't fix this problem. Sorry about that.
This comment was minimized by the moderator on the site
Hi, I have a problem about title, the title range of my table is A1:AI2, when I changed the code like that it doesn't work.

***Note: A1:C1 is the title range of your table. You can change it based on your needs.***
This comment was minimized by the moderator on the site
Hello, thanks so much for this. I'm looking to modify the macro such that it will create a sheet for each row of a column and within each sheet have a function (average) that I can populate data into and in turn have the outcome linked back into the original sheet. Is this possible? I can try to clarify further if this doesn't make sense or is ambiguous.
This comment was minimized by the moderator on the site
Hi, is there a code which would add only 1 new sheet each time the macro is run, eg 1st time the new sheet would be named on the contents of cell A1, 2nd time the macro was run the new sheet would be named on the contents of A2 etc. thanks in anticipation
This comment was minimized by the moderator on the site
Hello, used this code and worked, but If I want select the more then one rows in header, what will be change in the code ? I have multiple lines in the sheet which I want in every sheet.
This comment was minimized by the moderator on the site
Hello, did you figured out how?
This comment was minimized by the moderator on the site
Hello! I just used this code and it worked! In addition to creating a new sheet for each entry, I want to transpose it to columns and can't figure it out. So for the above example, the output for Nana would look like this - Name NanaScore 86No. 2
This comment was minimized by the moderator on the site
<p> Nana
86
2</p>
This comment was minimized by the moderator on the site
How to reference the use of the code above (credit) ? Is it possible to modify the code ?
This comment was minimized by the moderator on the site
Hi, this is an open communication platform. The code is allowed to reference and modify.
This comment was minimized by the moderator on the site
Nevermind it was hidden trailing spaces. I used the TRIM feature and cleaned it up. Having a row count (line count really so rows -1 prepended to the sheet would be amazing)
This comment was minimized by the moderator on the site
Please can i get help on how to automatically name the sheets using a particular column. This is for the row to sheet VBA. See below

Sub RowToSheet()

Dim xRow As Long

Dim I As Long

With ActiveSheet

xRow = .Range("A" & Rows.Count).End(xlUp).Row

For I = 1 To xRow

Worksheets.Add(, Sheets(Sheets.Count)).Name = "Row " & I

.Rows(I).Copy Sheets("Row " & I).Range("A1")

Next I

End With

End Sub
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations