Hey Guys/Girls,
I'm a first time poster, so please bear with me if I am not 100% spot on with my question.
I have a spreadsheet of data that contains multiple item numbers (one per row) and one column in that list has comma-delim data (2 characters).
It's currently taking 3 employees 2 whole days to sift through this report in order to extract what they need. If we are able to take this data (attached) and blow it out so that we create separate rows for each of the Product Code, it would save a ton of work.
To summarize, I need a way to take all of the comma-delim 2-digit codes in Column O and make them go to one in each row, but also copy all of the data from the row it's in to the single row. In the current example, Row 2 would not change, then Row 3 would be Item 1234 and Product CodeAB along with everything else in the current row copied to that row. Then, Row 4 would be Item 1234 and Product Code AC with everything else in the current row copied to that row.
Finally, the actual data set is 2,455 rows long before I would run the macro so the result could potentially be 400-500,000 rows of data. Also, I would need all columns to be copied over since all columns are used at some point in the data.
P.S. I would like the macro to create the result in a new tab if at all possible....but it's not 100% required.
Thanks so much to whoever can provide assistance.
Take care.
Last edited by JMcDon1007; 05-19-2011 at 08:01 AM.
Try this.
Sub Test() Dim TargetSheet As Worksheet Dim N As Long Dim M As Long Dim ProductCodeArray Sheets.Add Set TargetSheet = ActiveSheet Sheets("Sheet1").Activate Rows(1).Copy Destination:=TargetSheet.Rows(1) For N = 2 To Cells(Rows.Count, 1).End(xlUp).Row ProductCodeArray = Split(Cells(N, 15), ",") For M = 0 To UBound(ProductCodeArray) Rows(N).Copy Destination:=TargetSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) TargetSheet.Cells(Rows.Count, 1).End(xlUp).Offset(0, 14) = ProductCodeArray(M) Next M Next N TargetSheet.Activate End Sub
Open up the VBA editor by hitting ALT F11
Insert a new module by hitting Insert - Module
Paste the macro into the empty sheet
Hit ALT F11 to get back to the worksheet.
Run the macro by going to tools-macro in Excel 2003 or the view ribbon in Excel 2007.
Martin
Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.
If my solution has saved you time and/or money, please consider donating to Cancer Research UK.
This worked! Thank you again for your help. I had to tweak a few things due to differences in subsequent sheets but overall it got me on the track I needed to be on. I appreciate all the help.
Take care.
I just uncovered an issue. I was stress testing this code with a high volume spreadsheet which would have produced well over 400,000 records. The macro ran fine; however, the spreadsheet is saved as a .xls file; therefore, it hits a wall at ~65,000 records. I know that the new Excel 2007 spreadsheets will accommodate a much greater volume of records.
My questions are: If I simply save the original spreadsheet as a .xlsx file, then run the macro, will it produce the larger volume I'm looking for (past ~65,000 rows)? And if so, would there be any necessary changes in the code to facilitate the .xlsx file?
Thanks again for all your help!
Hi JMcDon1007
In Excel 2007, try saving the file as an xlsm (macro enabled) file. See if that helps. In reading the code as posted, it doesn't appear to require modification.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Thank you Sir! I also discovered that by simply saving the file as an Excel 2007 file would solve the issue. Per your instruction, I will mark this as closed.
Thanks again to everyone for all of their help.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks