LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Insert rows by group and copy value

I want to insert two rows by every customerID. Leave one of the rows
blank. The first cell of other row should have the value of Column F,
the name of the customerID.

This is the original data
CustomerID A B C D Name
1102367 2 6500 0 58 ABC
1102367 5 6500 5 5 ABC
1102451 6 93165 8 48 XYZ
1102451 7 7 11 91 XYZ
1102451 5 3 14 134 XYZ
1102581 5 6 17 177 BBC
1102581 3 9 20 220 BBC
1102581 80 12 23 263 BBC
1103177 50 15 26 306 AAA
1103177 822154 18 29 349 AAA

Want to convert it to
CustomerID A B C D Name

ABC
1102367 2 6500 0 58 ABC
1102367 5 6500 5 5 ABC

XYZ
1102451 6 93165 8 48 XYZ
1102451 7 7 11 91 XYZ
1102451 5 3 14 134 XYZ

BBC
1102581 5 6 17 177 BBC
1102581 3 9 20 220 BBC
1102581 80 12 23 263 BBC

AAA
1103177 50 15 26 306 AAA
1103177 822154 18 29 349 AAA

I got the following code but it paste over the value

Sub test()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim botCell As Range
Dim topCell As Range
Dim wks As Worksheet


Set wks = ActiveSheet

With wks
.Columns(1).Delete

FirstRow = 2
.Rows(FirstRow).Insert
.Cells(FirstRow, "A").Value = ""
LastRow = .Cells(.Rows.Count, "A").End(xlUp).row

Set topCell = .Cells(LastRow, "A")
Set botCell = .Cells(LastRow, "A")
For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value
Then
Set topCell = .Cells(iRow - 1, "A")
Else
If topCell.Address = botCell.Address Then
'do nothing
Else
botCell.Offset(1, 0).EntireRow.Insert
botCell.Offset(1, 0).EntireRow.Insert

.Cells(iRow, "A").Value = .Cells(iRow + 1, "F")

End If
Set botCell = .Cells(iRow - 1, "A")
Set topCell = .Cells(iRow - 1, "A")
End If
Next iRow

End With


End Sub

I appreciate your help.

Faye
 
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
Copy/Insert rows Niniel Excel Discussion (Misc queries) 2 August 31st 07 10:28 PM
Copy/Insert rows with formulas GregR Excel Worksheet Functions 4 April 26th 05 10:29 PM
Copy/Insert Rows Help needed Dean Goodmen Excel Programming 14 November 19th 04 08:59 AM
Copy Rows and insert these rows before a page break AQ Mahomed Excel Programming 0 June 8th 04 09:09 AM
Copy insert rows TonyG Excel Programming 0 October 30th 03 12:14 AM


All times are GMT +1. The time now is 08:01 AM.

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

About Us

"It's about Microsoft Excel"