Insert Row

Peco73267326

New Member
Joined
Jun 7, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,

I need help.
in column "B" I have a list of some tools and I need to insert an empty row. Example "B2:B5" I have tool 1001 and then I need to insert a blank row.
Every week I have a different number of lines

1686128331552.png
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this

VBA Code:
Sub Rows_Insert()
    Dim sh As Worksheet
    Dim LstRw As Long, x

    Set sh = ActiveSheet
    With sh
        LstRw = .Cells(.Rows.Count, "A").End(xlUp).Row

        For x = LstRw To 3 Step -1
            If .Cells(x, 1) <> .Cells(x - 1, 1) Then
                .Cells(x, 1).EntireRow.Insert
            End If
        Next
    End With
    
End Sub
 
Upvote 0
Hi
What about
VBA Code:
Sub test()
    Dim x&, i&
    x = Cells(Rows.Count, 2).End(xlUp).Row
    Cells(2, 10000).Resize(x).Formula = "=($B2 =$B1)*1"
    For i = x To 3 Step -1
        If Cells(i, 10000) = 0 Then Cells(i, 10).EntireRow.Insert
    Next
    Columns(10000).ClearContents
End Sub
 
Upvote 0
Ah, good point, My code should have used Column B, not Column A

VBA Code:
       Sub Rows_Insert()
Dim sh As Worksheet
Dim LstRw As Long, x

Set sh = ActiveSheet
With sh
LstRw = .Cells(.Rows.Count, "B").End(xlUp).Row

For x = LstRw To 3 Step -1
If .Cells(x, 2) <> .Cells(x - 1, 2) Then
.Cells(x, 2).EntireRow.Insert
End If
Next
End With
   
End Sub
 
Upvote 0
Sub test() Dim x&, i& x = Cells(Rows.Count, 2).End(xlUp).Row Cells(2, 10000).Resize(x).Formula = "=($B2 =$B1)*1" For i = x To 3 Step -1 If Cells(i, 10000) = 0 Then Cells(i, 10).EntireRow.Insert Next Columns(10000).ClearContents End Sub
it is running :D I am Happy a thank you veryyyyyyyyyyy much.
 
Upvote 0
it is running :D I am Happy a thank you veryyyyyyyyyyy much.
You are very welcome
Thank you for the feed back
Be happy and safe
Let me provide another version
could be faster
VBA Code:
Sub test()
    Dim x&, i&
    Dim r As Range
    x = Cells(Rows.Count, 2).End(xlUp).Row
    Cells(2, 10000).Resize(x).Formula = "=($B2 =$B1)*1"
    For i = x To 3 Step -1
        If Cells(i, 10000) = 0 Then
            If r Is Nothing Then
                Set r = Cells(i, 1)
            Else
                Set r = Union(r, Cells(i, 1))
            End If: End If
    Next
    r.EntireRow.Insert
    Columns(10000).ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,393
Members
449,446
Latest member
CodeCybear

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top