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

วิธีแทรกแถวว่างเหนือข้อความเฉพาะใน Excel

doc แทรกแถวเหนือข้อความเฉพาะ 1 2 doc แทรกแถวเหนือข้อความเฉพาะ 2

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

แทรกแถวว่างเหนือข้อความเฉพาะด้วยรหัส VBA

แทรกแถวว่างเหนือข้อความเฉพาะด้วย Kutools for Excel


แทรกแถวว่างเหนือข้อความเฉพาะด้วยรหัส VBA

หากต้องการแทรกแถวว่างเหนือข้อความที่ระบุด้วยตนเองทีละรายการจะเสียเวลามากที่นี่ฉันจะสร้างรหัส VBA เพื่อให้คุณแทรกแถวว่างเหนือค่าเซลล์ที่ระบุพร้อมกัน

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

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

รหัส VBA: แทรกแถวว่างเหนือข้อความเฉพาะอย่างรวดเร็ว

Sub test1()
'updateby Extendoffice
    Dim i As Long
    Dim xLast As Long
    Dim xRng As Range
    Dim xTxt As String
    On Error Resume Next
    xTxt = Application.ActiveWindow.RangeSelection.Address
    Set xRng = Application.InputBox("please select the column with specific text:", "Kutools for Excel", xTxt, , , , , 8)
    If xRng Is Nothing Then Exit Sub
    If (xRng.Columns.Count > 1) Then
        MsgBox "the selected range must be one column", , "Kutools for Excel"
        Exit Sub
    End If
    xLast = xRng.Rows.Count
    For i = xLast To 1 Step -1
      If InStr(1, xRng.Cells(i, 1).Value, "Mike") > 0 Then
        Rows(xRng.Cells(i, 1).Row).Insert shift:=xlDown
      End If
    Next
End Sub

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

doc แทรกแถวเหนือข้อความเฉพาะ 3

4. จากนั้นคลิก OK แถวว่างถูกแทรกไว้เหนือข้อความเฉพาะ“ Mike”

หมายเหตุ: ในโค้ดด้านบนคุณสามารถเปลี่ยนค่าข้อความ“ไมค์” เป็นค่าอื่น ๆ ที่คุณต้องการจากสคริปต์ ถ้า InStr (1, xRng.Cells (i, 1) .Value, "Mike")> 0 แล้วก็.


แทรกแถวว่างเหนือข้อความเฉพาะด้วย Kutools for Excel

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

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

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

1. เลือกช่วงข้อมูลที่คุณต้องการใช้

2. จากนั้นคลิก Kutools > เลือก > เลือกเซลล์เฉพาะดูภาพหน้าจอ:

3. ใน เลือกเซลล์เฉพาะ ใหเลือก เซลล์ ภายใต้ ประเภทการเลือกแล้วระบุเกณฑ์ที่คุณต้องการภายใต้ ประเภทเฉพาะ ในกรณีนี้ฉันจะเลือก เท่ากับ จาก ประเภทเฉพาะและป้อนชื่อที่ฉันต้องการเลือกดูภาพหน้าจอ:

doc แทรกแถวเหนือข้อความเฉพาะ 5

4. จากนั้นคลิก Ok ปุ่มเซลล์ทั้งหมดที่เป็นค่าไมค์จะถูกเลือกในครั้งเดียวดูภาพหน้าจอ:

doc แทรกแถวเหนือข้อความเฉพาะ 6

5. หลังจากเลือกเซลล์ข้อความที่ต้องการแล้วโปรดคลิก หน้าแรก > สิ่งที่ใส่เข้าไป > แทรกแถวแผ่นงานและแถวว่างจะถูกแทรกเหนือข้อความที่เลือกดูภาพหน้าจอ:

doc แทรกแถวเหนือข้อความเฉพาะ 7 2 doc แทรกแถวเหนือข้อความเฉพาะ 2

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


Demo: แทรกแถวว่างเหนือข้อความเฉพาะด้วย 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 (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I try do it to put a blank row after every non-empty cell, but excel says. "That command cannot be used on multiple selections"
Why it dosnt work for me???
This comment was minimized by the moderator on the site
Is there a way not to appears dialog box with pop out to remind me to select the column data which contains specific text I want to insert row above, If a specified cell is filled with data, then process run automatically , without promptings, and insert row above?
This comment was minimized by the moderator on the site
This has been amazing for the data I have. I was wondering if you could help me one step further. I have been able to split my data based on this, but then I need to colour code my groups of data. When I split my data I have a variable number of rows from 1-50, and I have 36 columns of data including 32 columns that I need to compare the values within to the top row. I am currently manually selecting each group (as separated by a blank row) and then using ctrl+shift+| to highlight column differences, and formatting those cells to highlight the differences.


Is there anyone who could write a code to select and format those column differences within the groupings, using the blank row as a separator?
This comment was minimized by the moderator on the site
Hi, i have a similar problem as the one above. What if i want to select the cell below a specified criteria? For example, you can use the example from above. i want to select the cell below "Mike". is there any easy way out?
This comment was minimized by the moderator on the site
@SSJ did you ever find a solution?
This comment was minimized by the moderator on the site
Hello, guys,

To insert blank rows below a specific cell value, you can apply the following code:

Sub BlankLine()
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set WorkRng = WorkRng.Columns(1)
xLastRow = WorkRng.Rows.Count
Application.ScreenUpdating = False
For xRowIndex = xLastRow To 1 Step -1
Set Rng = WorkRng.Range("A" & xRowIndex)
If Rng.Value = "Mike" Then
Rng.Offset(1, 0).EntireRow.Insert Shift:=xlDown
End If
Next
Application.ScreenUpdating = True
End Sub

Please change the criteria "Mike" to your own cell value.

Hope it can help you, thank you!
This comment was minimized by the moderator on the site
thank you! its worked.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations