Code to add entire row based on cell

Svedde

New Member
Joined
Sep 2, 2015
Messages
2
Hi everyone,

I’m completely new to the macro functionality and I’ve found a code online that does almost everything that I want for my purpose. I want to add ONE entire blank row below every time something (in my case the letter “G”) appears in a cell within a given range (or in my case, rather within a column). This code does this for me, but since the column to scan always is Column C, I’d like to add that to the code so that I don’t have to set the scan area every time using the code. Can that be done? Here’s the code:

Sub BlankLine()
'Updateby20150203
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type: = 8)
Set WorkRng = WorkRng.Columns(1)
xLastRow = WorkRng.Rows.Count
Application.ScreenUpdating = False
For xRowIndex = xLastRow To 1 Step - 1
Set Rng = WorkRng.Range("A" & xRowIndex)
If Rng.Value = "G" Then
Rng.Offset(1, 0).EntireRow.Insert Shift: = xlDown
End If
Next
Application.ScreenUpdating = True
End Sub

Best Regards / Med vänliga hälsningar,
Henrik
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi,

Try this:

Code:
Sub Test()

Dim lngLastRow As Long
Dim lngEachRow As Long


lngLastRow = Range("C" & Rows.Count).End(xlUp).Row


For lngEachRow = lngLastRow To 2 Step -1
    If Range("C" & lngEachRow) = "G" Then
        Rows(lngEachRow + 1).Insert
    End If
Next lngEachRow


End Sub

Dom
 
Upvote 0

Forum statistics

Threads
1,215,500
Messages
6,125,168
Members
449,211
Latest member
ykrcory

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