Insert rows in depending on criteria in variable columns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to thank everyone in advance for looking into this for me.

I currently have a macro that inserts a blank row after every cell in column
A that changes. See below:

Tom
Tom
Tom
Dick
Dick
Harry
Harry
Harry

The macro would insert a row after the 3rd Tom, the 2nd Dick, and the third
Harry. I have come across the need to be able to pick which column I want the
macro to examine. Sometimes column A, sometimes AB, etc. Any suggestions?

Thanks again

Jeff
 
hi,
first think to come to mind....
you can use inputbox to prompt for parameters.
in this case it might be column letter.
but since you didn't post any code, i have no idea where
to put it or how to use it.
 
Sorry. Had it on my clipboard and everything. Here it is.

Sub InsertRows()
Dim cRows As Long
Dim i As Integer

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(i, "A") <> Cells(i + 1, "A") Then
Cells(i + 1, "A").EntireRow.Insert
End If
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top