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!!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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