doc在特定文字上方插入一行1 2 doc在特定文字上方插入一行2

在工作表上工作時,您是否曾嘗試在列中的特定文本上方插入空白行? 例如,A列中有一些名稱,現在,我想在包含名稱“ Mike”的單元格上方插入空白行,如左圖所示,也許,您沒有直接方法可以在Excel中解決此任務。 本文,我將討論一些在Excel中處理此工作的好技巧。


在特定文本上方插入空白行 Kutools for Excel



1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下宏粘貼到 模塊 窗口。


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
End Sub

3。 然後按 F5 鍵運行此代碼,然後會彈出一個對話框,提醒您選擇包含要在上面插入行的特定文本的列數據,請參見屏幕截圖:


4。 然後點擊 OK 按鈕,空白行已插入到特定文本“ Mike”上方。

備註:在上面的代碼中,您可以更改文本值“麥克風”到腳本中所需的其他任何值 如果InStr(1,xRng.Cells(i,1).Value,“ Mike”)> 0 然後.

在特定文本上方插入空白行 Kutools for Excel

如果你有 Kutools for Excel,其 選擇特定的單元格 功能,您可以先選擇指定的單元格值,然後應用Excel的“插入工作表行”實用程序一次插入空白行。

Kutools for Excel : 帶有300多個便捷的Excel加載項,可以在30天內免費試用

安裝後 Kutools for Excel,請執行以下操作:

1。 選擇您要使用的數據范圍。

2。 然後點擊 庫工具 > 選擇 > 選擇特定的單元格,請參見屏幕截圖:

3。 在 選擇特定的單元格 對話框中選擇 細胞選擇類型,然後在 特定類型 部分,在這種情況下,我將選擇 等於 來自 特定類型,然後輸入我要選擇的名稱,請參見屏幕截圖:


4。 然後點擊 Ok 按鈕,立即選擇所有值為Mike的單元格,請參見屏幕截圖:


5. 選擇特定的文本單元格後,請單擊 首頁 > 插入 > 插入圖紙行,空白行將插入到所選文本的上方,請參見屏幕截圖:

doc在特定文字上方插入一行7 2 doc在特定文字上方插入一行2

 下載並免費試用 Kutools for Excel 現在 !

演示:在特定文本上方插入空白行 Kutools for Excel

Kutools for Excel:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!


熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

增強您的 Excel 技能 Kutools for Excel,體驗前所未有的效率。 Kutools for Excel 提供 300 多種高級功能,可提高工作效率並節省時間。  點擊此處獲取您最需要的功能...


Office Tab 為 Office 帶來選項卡式界面,讓您的工作更輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 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
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