Macro Range [Solved/Closed]

Report
Posts
3
Registration date
Thursday August 8, 2013
Status
Member
Last seen
August 9, 2013
-
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
-
Hello,



I am somewhat inexperienced in the world of macros in excel. I have a looping macro that runs from the bottom and i want it to stop at a specific row. Below is the macro.

Can anyone help me with this?

Thanks,

Jim

Sub InsertRows()

Dim r As Long, mcol As String, i As Long

' find last used cell in Column A
r = Cells(Rows.Count, "A").End(xlUp).Row

' get value of last used cell in column A
mcol = Cells(r, 1).Value

' insert rows by looping from bottom
For i = r To 2 Step -1
If Cells(i, 1).Value <> mcol Then
mcol = Cells(i, 1).Value
Rows(i + 1).Insert
End If
Next i

End Sub

4 replies

Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
797
i wonder can you not do this in this code

For i = r To 2 Step -1

instead of 2 can you not type some other number 7 or l9 or 12
Posts
3
Registration date
Thursday August 8, 2013
Status
Member
Last seen
August 9, 2013

Thanks vankat. That worked perfectly. If I knew what I was doing I would have probably known that.

Thanks again,
Jim
Posts
3
Registration date
Thursday August 8, 2013
Status
Member
Last seen
August 9, 2013

venkat

As I said, your solution worked great. The only problem is that the person I was doing this for wants the column and stop row to be those of the selected cell. I'm sure you know that you never get the whole story in the beginning.

Thanks,

Jim
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
797
I seem to have answered this perhaps to a private message . please see that.

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!