VBA Duplicate row when column contains specific text

Kriszilla

New Member
Joined
Sep 22, 2023
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
Hi,
I've always found the answers to my excel questions here.
But this one I can't seem to find.

I have an excel file containing a list of items
with descriptions of various lengts,

All items have a description L/R
And I need it to be split into L an R

I would be helped with a VBA code that copy's a row when cell in column B contains L/R
and insert a row below the actual row and paste it there so I can later adjust L/R to L and R
If the L/R would be adjusted bij the code would be even better.

Here is a image of what I would like to accomplish:
1695374198160.png
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi, welcome to the forum.

Let me know if this works for you ?

VBA Code:
Sub insertLR()

Application.ScreenUpdating = False
Dim LastRow, x As Long

    LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

    For x = LastRow To 1 Step -1
    
        If ActiveSheet.Cells(x, 2) = "L/R" Then
        
            ActiveSheet.Cells(x, 2) = "R"
            ActiveSheet.Range("A" & x).EntireRow.Copy
            ActiveSheet.Range("A" & x).EntireRow.Insert
            ActiveSheet.Cells(x + 1, 2) = "L"
        
        End If
    
    Next x

Application.ScreenUpdating = True

End Sub
 
Upvote 1
Solution
Great, glad we could help.

thanks for the feedback

Rob
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

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