A Challenge for you Excel experts

mljohn

Board Regular
Joined
Aug 26, 2004
Messages
196
Office Version
  1. 365
Platform
  1. Windows
I have a large list of parts that I want to change how the data is laid out.

It was laid out by the part number and which machines went to that part number. The machines were all together in one cell.

Now I want to have each machine have it's own row.

I'll need a way to automate the process since I have so many records.

I have a link to my Box.net account that shows an example spreadsheet.

http://www.box.net/shared/cl8l0vi9qh

I hope you are up to the challenge, I sure need the help.

Thanks

Matt
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
mljohn,

Thanks for the workbook.


Sample raw data in worksheet Sheet1:


Excel Workbook
ABCDEFGHIJ
1CategoryPrinterCompatible withOemPartNoMSEPartNoPremiumPartNoPageYieldPriceMSRPStreetPrice
2TONERBROTHERDCP-1200, 1400, Fax 4750, 5750, 8350p, 8750p, HL 1030, 1230, 1240, 1250, 1270n, 1435, 1440, 1470nDR40058-03-401458-03-401020,000$43.00$175.00$186.99
3TONERBROTHERDCP-7020, IntelliFax-2820, 2910,2920, HL-2040, 2070N, MFC-7220,7225N, 7420,7820NDR35058-03-351458-03-351012,000$47.00$95.00$119.99
4TONERBROTHERDCP-7030, 7040, 7045N, HL-2140, 2150N, 2170W, MFC-7320, 7340, 7345DN,7345N, 7440N, 7840WTN36002-03-361602-03-36042,600$29.50$51.00$71.99
5
Sheet1





After the macro in a new worksheet Results:


Excel Workbook
ABCDEFGHIJ
1CategoryPrinterCompatible withOemPartNoMSEPartNoPremiumPartNoPageYieldPriceMSRPStreetPrice
2TONERBROTHERDCP-1200DR40058-03-401458-03-401020,000$43.00$175.00$186.99
3TONERBROTHER1400DR40058-03-401458-03-401020,000$43.00$175.00$186.99
4TONERBROTHERFax4750DR40058-03-401458-03-401020,000$43.00$175.00$186.99
5TONERBROTHER5750DR40058-03-401458-03-401020,000$43.00$175.00$186.99
6TONERBROTHER8350pDR40058-03-401458-03-401020,000$43.00$175.00$186.99
7TONERBROTHER8750pDR40058-03-401458-03-401020,000$43.00$175.00$186.99
8TONERBROTHERHL1030DR40058-03-401458-03-401020,000$43.00$175.00$186.99
9TONERBROTHER1230DR40058-03-401458-03-401020,000$43.00$175.00$186.99
10TONERBROTHER1240DR40058-03-401458-03-401020,000$43.00$175.00$186.99
11TONERBROTHER1250DR40058-03-401458-03-401020,000$43.00$175.00$186.99
12TONERBROTHER1270nDR40058-03-401458-03-401020,000$43.00$175.00$186.99
13TONERBROTHER1435DR40058-03-401458-03-401020,000$43.00$175.00$186.99
14TONERBROTHER1440DR40058-03-401458-03-401020,000$43.00$175.00$186.99
15TONERBROTHER1470nDR40058-03-401458-03-401020,000$43.00$175.00$186.99
16
17
18
19TONERBROTHERDCP-7020DR35058-03-351458-03-351012,000$47.00$95.00$119.99
20TONERBROTHERIntelliFax-2820DR35058-03-351458-03-351012,000$47.00$95.00$119.99
21TONERBROTHER2910DR35058-03-351458-03-351012,000$47.00$95.00$119.99
22TONERBROTHER2920DR35058-03-351458-03-351012,000$47.00$95.00$119.99
23TONERBROTHERHL-2040DR35058-03-351458-03-351012,000$47.00$95.00$119.99
24TONERBROTHER2070NDR35058-03-351458-03-351012,000$47.00$95.00$119.99
25TONERBROTHERMFC-7220DR35058-03-351458-03-351012,000$47.00$95.00$119.99
26TONERBROTHER7225NDR35058-03-351458-03-351012,000$47.00$95.00$119.99
27TONERBROTHER7420DR35058-03-351458-03-351012,000$47.00$95.00$119.99
28TONERBROTHER7820NDR35058-03-351458-03-351012,000$47.00$95.00$119.99
29
30
31
32TONERBROTHERDCP-7030TN3602/3/36162/3/36042,600$29.50$51.00$71.99
33TONERBROTHER7040TN3602/3/36162/3/36042,600$29.50$51.00$71.99
34TONERBROTHER7045NTN3602/3/36162/3/36042,600$29.50$51.00$71.99
35TONERBROTHERHL-2140TN3602/3/36162/3/36042,600$29.50$51.00$71.99
36TONERBROTHER2150NTN3602/3/36162/3/36042,600$29.50$51.00$71.99
37TONERBROTHER2170WTN3602/3/36162/3/36042,600$29.50$51.00$71.99
38TONERBROTHERMFC-7320TN3602/3/36162/3/36042,600$29.50$51.00$71.99
39TONERBROTHER7340TN3602/3/36162/3/36042,600$29.50$51.00$71.99
40TONERBROTHER7345DNTN3602/3/36162/3/36042,600$29.50$51.00$71.99
41TONERBROTHER7345NTN3602/3/36162/3/36042,600$29.50$51.00$71.99
42TONERBROTHER7440NTN3602/3/36162/3/36042,600$29.50$51.00$71.99
43TONERBROTHER7840WTN3602/3/36162/3/36042,600$29.50$51.00$71.99
44
Results





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgData()
' hiker95, 03/26/2011
' http://www.mrexcel.com/forum/showthread.php?t=538961
Dim w1 As Worksheet, wR As Worksheet
Dim LR As Long, a As Long, Sp, s As Long, H As String, NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
Set wR = Worksheets("Results")
wR.Range("A1:J1").Value = w1.Range("A1:J1").Value
LR = w1.Cells(Rows.Count, 1).End(xlUp).Row
NR = 2
For a = 2 To LR Step 1
  H = ""
  H = Replace(w1.Cells(a, 3), " ", "")
  Sp = Split(H, ",")
  s = UBound(Sp) + 1
  wR.Range("A" & NR).Resize(s, 2).Value = w1.Range("A" & a).Resize(, 2).Value
  wR.Range("C" & NR).Resize(s).Value = Application.Transpose(Sp)
  wR.Range("D" & NR).Resize(s, 7).Value = w1.Range("D" & a).Resize(, 7).Value
  NR = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row + 3
Next a
wR.Range("C2:G" & NR + s).HorizontalAlignment = xlCenter
wR.Range("H2:J" & NR + s).NumberFormat = "[$$-409]#,##0.00_);([$$-409]#,##0.00)"
wR.UsedRange.Columns.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub


Then run the ReorgData macro.
 
Upvote 0
Hiker95 is amazing!!!!

Thank you.

When I saw the results when I ran the macro I felt like Homer Simpson when he thinks of Donuts.

This is one of the most beautiful things I have ever seen.

I never cease to be amazed at the quality of Excel experts I find on this site!!!

Thank you again, Hiker95

Matt Johnson
 
Upvote 0
Re: Hiker95 is amazing!!!!

Typed it, seems to work, so may as well post it.:)
Code:
Option Explicit
 
Sub TransposeStuff()
Dim wsSrc As Worksheet
Dim wsDst As Worksheet
Dim rngSrc As Range
Dim rngDst As Range
Dim NoItems As Long
Dim arrVals
 
    Set wsSrc = Worksheets("Sheet1")

    Set wsDst = Worksheets.Add

    Set rngSrc = wsSrc.Range("A2")
    
    Set rngDst = wsDst.Range("A2")
 
    rngSrc.Offset(-1).EntireRow.Copy rngDst.Offset(-1)
 
    While rngSrc.Value <> ""
 
        arrVals = Split(rngSrc.Offset(, 2), ",")
        NoItems = UBound(arrVals) + 1
        rngSrc.Resize(, 2).Copy rngDst.Resize(NoItems, 2)
        
        rngDst.Offset(, 2).Resize(NoItems) = Application.Transpose(arrVals)
        
        rngSrc.Offset(, 3).Resize(, 7).Copy rngDst.Offset(, 3).Resize(NoItems, 7)
        
        Set rngSrc = rngSrc.Offset(1)
        
        Set rngDst = rngDst.Offset(NoItems)
 
    Wend
 
    rngDst.Resize(, 10).EntireColumn.AutoFit
    
    Application.CutCopyMode = False
    
End Sub
 
Upvote 0
Thank you this one also worked. However I liked how Hiker95 put spaces in between the part numbers to keep all the same part numbers together.
 
Upvote 0
Another question:

I noticed that when I ran your macro that some of the machines didn't have their full name. See the 2 examples. The top one they didn't enter the "DCP-" on the 7040 and 7045N. The "HL-" was left off of the 2150N and the 2170W. The bottom group they did enter everything correctly and took no shortcuts.

Is there a way to have the program look for this and fix it. The format seems to be consistent.

Also, is there a way to highlight what I want to apply the macro to?


DCP-7030
7040
7045N
HL-2140
2150N
2170W
MFC-7320
7340
7345DN
7345N
7440N
7840W



DCP-8020
DCP-8025D
HL-1650
HL-1650N
HL-1650NPLUS
HL-1670N
HL-1850
HL-1870n
HL-5040
HL-5050
HL-5050LT
HL-5070N
MFC-8420
MFC-8420D
MFC-8820D
MFC-8820DN
 
Upvote 0
mljohn,

I will need to see your actual raw data.

You can post another workbook on box.net containing the raw data (sensative data changed), and the actual manually formatted output on worksheet Restuls.
 
Last edited:
Upvote 0
mljohn,

Your latest posted workbook on box.net only has one worksheet, but no raw data.


I will need to see your actual raw data.

You can post another workbook on box.net containing the raw data (sensative data changed), and the actual manually formatted output on worksheet Results.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top