Help with inserting a blank line on condition

  • Thread starter Thread starter microsatellite
  • Start date Start date
M

microsatellite

Hi,

I've been programming in other languages but am very new to VB and still
getting used to its syntax style - so I'm stuck with the simplest of
problems.

What I have is an excel spreadsheet (obviously). In column A there are
text strings (names) that have been sorted into groups. So basically
groups of names down the column. All I want to do is add a complete blank
row after each name group - the number of names in each group is not
consistent.

eg

Peter
Peter
Peter

Paul
Paul

Mary
Mary
Mary
Mary

Can someone provide some help here?

Thanks
 
Sub separategroups()
Dim lastrow as long, i as long
lastrow = cells(rows.count,1).end(xlup).row
for i = lastrow to 2 step -1
if cells(i,1).value <> cells(i -1,1).value then
rows(i).Insert
end if
Next
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