VBA SIMPLE - Inserting Partial Row based on text in a specified column

traderjoe

New Member
Joined
Nov 18, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I'm new to writing macros and I'm getting stuck on how to insert partial rows using macro script.
What I am trying to do is
- Insert cells/partial row in Columns D and E, and shift the rest of the data down if Column G contains the text "DUP"

' QAQCRowInsert Macro

Dim c As Range
For Each c In Range("G1:G99999")
If c.Value Like "DUP" Then
c.Offset(1, 0).EntireRow.Insert
End If
Next c
End Sub

This is the macro I currently have, can someone please help me edit it so that instead of entering an entire row, cells are only inserted in columns D and E

Many Thanks!!
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,410
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Maybe:
VBA Code:
Sub Tjoe()
Dim c As Range
For Each c In Range("G1:G" & Cells(Rows.Count, "G").End(xlUp).Row)
    If c.Value Like "*DUP*" Then
        c.Offset(1, -3).Resize(1, 2).Insert shift:=xlDown
    End If
Next c
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,126,986
Messages
5,621,992
Members
415,873
Latest member
fuulhouse

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
Top