Starting range at row 2

Serafin54

Board Regular
Joined
Apr 11, 2014
Messages
160
Office Version
  1. 2016
Platform
  1. Windows
Hello. I have the code below that inserts a blank row when the value in the selected column changes. It works great except that it inserts a blank row at row 2 because of the header. I am having a brain fart and not seeing how to exclude the header in the logic. Any help is appreciated.


VBA Code:
Public Sub InsertRowsAtChange(Control As IRibbonControl)
Dim rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Separate Changed Values"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For i = WorkRng.Rows.Count To 2 Step -1
    If WorkRng.Cells(i, 1).Value <> WorkRng.Cells(i - 1, 1).Value Then
        WorkRng.Cells(i, 1).EntireRow.Insert
    End If
Next
Application.ScreenUpdating = True
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Change your 2 to 3, i.e.
change this:
Rich (BB code):
For i = WorkRng.Rows.Count To 2 Step -1
to this:
Rich (BB code):
For i = WorkRng.Rows.Count To 3 Step -1
 
Upvote 1
Solution
Change your 2 to 3, i.e.
change this:
Rich (BB code):
For i = WorkRng.Rows.Count To 2 Step -1
to this:
Rich (BB code):
For i = WorkRng.Rows.Count To 3 Step -1


Gah! that's it. googly moogly. Thank you.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,977
Members
449,095
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