Macro Range

Solved/Closed
Jim Clanton Posts 3 Registration date Thursday August 8, 2013 Status Member Last seen August 9, 2013 - Aug 8, 2013 at 06:03 PM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Aug 10, 2013 at 12:14 AM
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 responses

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Aug 9, 2013 at 06:03 AM
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
0
Jim Clanton Posts 3 Registration date Thursday August 8, 2013 Status Member Last seen August 9, 2013
Aug 9, 2013 at 07:39 AM
Thanks vankat. That worked perfectly. If I knew what I was doing I would have probably known that.

Thanks again,
Jim
0
Jim Clanton Posts 3 Registration date Thursday August 8, 2013 Status Member Last seen August 9, 2013
Aug 9, 2013 at 10:16 AM
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
0
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Aug 10, 2013 at 12:14 AM
I seem to have answered this perhaps to a private message . please see that.
0