ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with inserting a blank line on condition (https://www.excelbanter.com/excel-programming/360177-help-inserting-blank-line-condition.html)

microsatellite

Help with inserting a blank line on condition
 
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


Tom Ogilvy

Help with inserting a blank line on condition
 
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

--
Regards,
Tom Ogilvy


"microsatellite" wrote in message
.com...
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





All times are GMT +1. The time now is 06:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com