I have a spreadsheet that lists all customers and order numbers, with each order number having a different line, and the customers shown multiple times.
I would like to merge this, so each customer number is shown once, and the order numbers shown in the following cells. I've attached an example sheet.
I've seen various methods explained, but can't figure them out, so I'd appreciate an example if anyone can help.
Cheers
Baz
Try this
Option Explicit Sub TransposeOrders() Dim wsData As Worksheet Dim LastRow As Long, RowNo As Long, ColNo As Long Dim StartRow As Long Dim RefNo As Long Dim c As Integer, i As Integer Set wsData = ActiveWorkbook.Worksheets("Sheet1") LastRow = Range("A" & Rows.Count).End(xlUp).Row With wsData.Sort .SortFields.Clear .SortFields.Add Key:=Range("A2:A" & LastRow), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal .SortFields.Add Key:=Range("B2:B" & LastRow), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal .SetRange Range("A1:B" & LastRow) .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With StartRow = 2 With wsData For RowNo = LastRow To StartRow Step -1 RefNo = .Range("A" & RowNo) Do While .Range("A" & RowNo - 1) = RefNo RowNo = RowNo - 1 c = c + 1 Loop For ColNo = 2 To 2 + c .Cells(RowNo, ColNo) = .Range("B" & RowNo + i) i = i + 1 Next .Range(.Cells(RowNo + 1, 1), .Cells(RowNo + c, 1)).EntireRow.Delete i = 0 c = 0 Next End With End Sub
Hope this helps
Last edited by Marcol; 07-02-2010 at 08:05 AM. Reason: Added option explicit, & updated attachment
If you need any more information, please feel free to ask.
However, if this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
Also
If you are satisfied by any members response to your problem please consider using the small Star icon botom left of thier post to show your appreciation.
Thanks Marcol
I've not been able to get the macro working. I've not really used them before.
Is there any chance you could apply it to the spreadsheet I attached so I can see how it works?
I really appreciate your help with this.
That was the spreadsheet you attached.
The only differences were that
.
1/. I asumed that your headers were in row 1 in your real worksheet, and data began in row 2.
2/. I added a few lines for testing purposes
If this is not the case, please post a sample sheet, that clearly shows the sheet structure you are using.
I will be happy to help from thereon, and give any explanation you might need.
Cheers
i have a similar problem with the one above.
can anyone help me to achieve the result that is in the file attached.
regards,
sebastian
probebun.xls
Hi sensey1
Welcome to the forum ...
Read this Forum Rules before the moderators get you...
Forum Rules
This thread is nearly 2 years old!2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread.
If you can Edit/Delete your post, do so, if not you'll need to ask a moderator to help you.
Cheers
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks