Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Insert row at change macro - how to change it.

Some on this board wrote a macro for me to insert a blank row after a column
of names and it works wonderfully for last names. However if doesn't put a
blank row between people with the same last name, but different first names.
Is it possible for someone to look at this macro and change it for me?
Thanks, I'll be very grateful.

'Sandy Mann July 1st, 2007
Dim LastRow As Long
Dim X As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False

For X = LastRow To 3 Step -1
If Cells(X, 1).Value < Cells(X - 1, 1).Value Then
If Cells(X, 1).Value < "" Then
If Cells(X - 1, 1).Value < "" Then
Cells(X, 1).EntireRow.Insert Shift:=xlDown
End If
End If
End If
Next X
Application.ScreenUpdating = True

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 225
Default Insert row at change macro - how to change it.

Looks like your last names are in Col A...
If first names are in Col B then use this
(just changed 1 i.e. Col A to 2 i.e. Col B)
It is assumed that data is sorted on Last name and then on first name...

Sub insertRow()
Dim LastRow As Long
Dim X As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Application.ScreenUpdating = False

For X = LastRow To 3 Step -1
If Cells(X, 2).Value < Cells(X - 1, 2).Value Then
If Cells(X, 2).Value < "" Then
If Cells(X - 1, 2).Value < "" Then
Cells(X, 2).EntireRow.Insert Shift:=xlDown
End If
End If
End If
Next X
Application.ScreenUpdating = True


End Sub
"cathit" wrote:

Some on this board wrote a macro for me to insert a blank row after a column
of names and it works wonderfully for last names. However if doesn't put a
blank row between people with the same last name, but different first names.
Is it possible for someone to look at this macro and change it for me?
Thanks, I'll be very grateful.

'Sandy Mann July 1st, 2007
Dim LastRow As Long
Dim X As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False

For X = LastRow To 3 Step -1
If Cells(X, 1).Value < Cells(X - 1, 1).Value Then
If Cells(X, 1).Value < "" Then
If Cells(X - 1, 1).Value < "" Then
Cells(X, 1).EntireRow.Insert Shift:=xlDown
End If
End If
End If
Next X
Application.ScreenUpdating = True

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro that will change the font of a cell if i change a value jk Excel Discussion (Misc queries) 2 July 29th 08 04:39 PM
Insert a day on change of other cell Namster Excel Worksheet Functions 5 January 22nd 07 10:53 PM
Insert lines at each change in value LisaVH Excel Discussion (Misc queries) 3 December 13th 06 04:04 PM
I can't add a row How can I change it to let me insert a row buncogal Excel Discussion (Misc queries) 2 February 27th 06 03:50 PM
How do I change the default color of the tag for insert c... ntwrkengnr Excel Discussion (Misc queries) 1 December 17th 04 06:34 PM


All times are GMT +1. The time now is 02:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"