Add row under value thn copy data down into new row VBA

cmschmitz24

Board Regular
Joined
Jan 27, 2017
Messages
150
Hello,

I need help writing a code that will add a blank row underneath each unique value in column B.
Then in the blank row, copy/paste the data from the row above it.

Example

A2 00037924 B2 0 C2 CP
A3 00039761 B3 1 C3 AS

will look like

A2 00037924 B2 0 C2 CP
A3 00037924 B3 0 C3 CP
A4 00039761 B4 1 C4 AS
A5 00039761 B5 1 C5 AS

Thanks!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
By "unique value" do you mean that all the values in column B are unique (no duplicates) or that there are duplicate values and you want one row added for each unique value? Does column B contain the 8 digit number?
 
Upvote 0
If there are no duplicates in col B, do you simply want to create 2 rows for every row in the sheet?
 
Upvote 0
How about
Code:
Sub DuplicateRows()

   Dim Cnt As Long
   
   For Cnt = Range("A" & Rows.Count).End(xlUp).row To 2 Step -1
      Rows(Cnt + 1).Insert
      Rows(Cnt).Resize(2).FillDown
   Next Cnt
End Sub
 
Upvote 0
How about
Code:
Sub DuplicateRows()

   Dim Cnt As Long
   
   For Cnt = Range("A" & Rows.Count).End(xlUp).row To 2 Step -1
      Rows(Cnt + 1).Insert
      Rows(Cnt).Resize(2).FillDown
   Next Cnt
End Sub

Works perfect. Thanks again, Fluff! :)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

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