Inserting Rows Macro -- please help!!

  • Thread starter Thread starter tratliff
  • Start date Start date
T

tratliff

I have a worksheet with @ 8000 rows.

The information in this worksheet is for @ 40 different customers bu
they are all together right now.

What I want is for a blank row to be inserted when the customer nam
changes.

For example:

if rows 3-39 are for ABC Co., Inc and rows 40-78 are for 123 Co., Inc

I want a blank row to be inserted between rows 39 and 40.

Any suggestions?
 
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



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
I have a worksheet with @ 8000 rows.

The information in this worksheet is for @ 40 different customers but
they are all together right now.

What I want is for a blank row to be inserted when the customer name
changes.

For example:

if rows 3-39 are for ABC Co., Inc and rows 40-78 are for 123 Co., Inc

I want a blank row to be inserted between rows 39 and 40.

Any suggestions??

Assuming your names start in cell A1

Sub InsertRow()
Dim x As Integer
x = 1
Do While Range("a1").Offset(x, 0) <> ""
If Range("a1").Offset(x, 0) <> Range("a1").Offset(x - 1, 0) Then
Range("a1").Offset(x, 0).EntireRow.Insert
x = x + 1
End If
x = x + 1
Loop
End Sub

__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________
 
Just out of curiosity, why would you want to put blank rows in a
database?

Wouldn't it be better if you used an advanced filter on another sheet
to view each company when you want to see them.

If you have blank lines, everytime you enter new data you will have to
sort out the blank lines and then insert the blank rows again.

Lynn :)
 
i need to insert the rows so I can do some formulas this workbook is no
used as a database, it is used to analyze data.

thanks
 

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