Add a blank row to a table in-between each unique values

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have a table (table1) on sheet1. in the very first column [ItemID] I have a list of parts where there are many duplicates (which is to be expected). Is there a way to instert a blank row where the part number does not eaqual the or is not the same as the row above it?

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this in a standard module:
VBA Code:
Sub test()
    Dim rng As Range, nextRng As Range
    Set rng = Range("A:A").Find(Cells(1, 1).Value, , xlValues, xlWhole, xlByRows, xlPrevious)
    Do While Not IsEmpty(rng.Offset(1, 0))
    If rng.Offset(1, 0) <> rng Then
        Set nextRng = rng.Offset(1, 0)
        nextRng.Insert Shift:=xlDown
        Set rng = Range("A:A").Find(nextRng.Value, , xlValues, xlWhole, xlByRows, xlPrevious)
    End If
    Loop
End Sub
Note that this only works if the upper leftmost cell in the table is A1.
 
Upvote 0
Another option:
VBA Code:
Sub a1160395a()
'https://www.mrexcel.com/board/threads/add-a-blank-row-to-a-table-in-between-each-unique-values.1160395/
Dim i As Long
Application.ScreenUpdating = False

With ActiveSheet.ListObjects("Table1").Range.Columns(1)
    For i = .Rows.Count + 1 To 3 Step -1
        Do
            i = i - 1
            If i = 2 Then Exit For
        Loop While .Cells(i) = .Cells(i - 1)
            .Rows(i).Insert
            i = i + 1
    Next
End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Thank you both. I tried both and they both work. Very much appreciate your time and help!
 
Upvote 0
You're welcome, glad to help & thanks for the feedback. :)
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,788
Members
449,049
Latest member
greyangel23

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