Skip to main content

How to insert blank row above specific text in Excel?

doc insert row above specific text 1  2 doc insert row above specific text 2

When you work on a worksheet, have you ever tried to insert blank row above a specific text in a column? For example, there are some names in column A, now, I want to insert blank rows above the cells which contain the name “Mike” as the left screenshot shown, maybe, there are no direct way for you to solve this task in Excel. This article, I will talk about some good tricks for dealing with this job in Excel.

Insert blank row above specific text with VBA code

Insert blank row above specific text with Kutools for Excel


Insert blank row above specific text with VBA code

To insert blank row above the specific text manually one by one will waste lots of time, here, I will create a VBA code for you to insert the blank row above specific cell value at once.

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and then paste the following macro in the Module Window.

VBA code: Insert blank row above specific text quickly

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. Then press F5 key to run this code, and a dialog box will pop out to remind you select the column data which contains specific text you want to insert row above, see screenshot:

doc insert row above specific text 3

4. And then click OK button, the blank rows have been inserted above the specific text “Mike”.

Note: In the above code, you can change the text value “Mike” to any other values that you desired from the script If InStr(1, xRng.Cells(i, 1).Value, "Mike") > 0 Then.


Insert blank row above specific text with Kutools for Excel

If you have Kutools for Excel, with its Select Specific Cells feature, you can select the specified cell values first, and then apply the Insert Sheet Rows utility of Excel to insert the blank rows at once.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days

After installing Kutools for Excel, please do as follows:

1. Select the data range that you want to use.

2. Then click Kutools > Select > Select Specific Cells, see screenshot:

3. In the Select Specific Cells dialog box, select Cell under the Selection type, and then specify the criteria that you need under the Specific type section, in this case, I will choose Equals from the Specific type, and enter the name that I want to select, see screenshot:

doc insert row above specific text 5

4. Then click Ok button, all the cells which value is Mike are selected at once, see screenshot:

doc insert row above specific text 6

5. After selecting the specific text cells, please click Home > Insert > Insert Sheet Rows, and the blank rows will be inserted above the selected text, see screenshots:

doc insert row above specific text 7  2 doc insert row above specific text 2

 Download and free trial Kutools for Excel Now !


Demo: Insert blank row above specific text with Kutools for Excel

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
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