I need a macro for transferring data from rows to columns (Example provided)

Greenej3

New Member
Joined
Oct 5, 2015
Messages
4
I need help with a macro that will transform the following table:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Component P/N[/TD]
[TD]Rev[/TD]
[TD]Qty[/TD]
[TD]BUn[/TD]
[TD]Description[/TD]
[TD]Mfg Name[/TD]
[TD]Mfr Part Number[/TD]
[/TR]
[TR]
[TD]130-158-01-02[/TD]
[TD][TABLE="width: 30"]
<tbody>[TR]
[TD="width: 30"]D2[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]1[/TD]
[TD][TABLE="width: 31"]
<tbody>[TR]
[TD="width: 31"]EA[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 216"]
<tbody>[TR]
[TD="width: 216"]Display/System uP,Jabroni[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 100"]
<tbody>[TR]
[TD="width: 100"]220-819-01-00[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 30"]
<tbody>[TR]
[TD="width: 30"]G3[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]1[/TD]
[TD][TABLE="width: 31"]
<tbody>[TR]
[TD="width: 31"]EA[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 216"]
<tbody>[TR]
[TD="width: 216"]PCBA,System Contlr,Jabroni[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 100"]
<tbody>[TR]
[TD="width: 100"]402-745-01-00[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD]23[/TD]
[TD][TABLE="width: 31"]
<tbody>[TR]
[TD="width: 31"]EA[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 216"]
<tbody>[TR]
[TD="width: 216"]CAP,X5R,123FG,26V,9%,0806[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][TABLE="width: 188"]
<tbody>[TR]
[TD="width: 188"]Taiyo-Yuden[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 119"]
<tbody>[TR]
[TD="width: 119"]TMK105BJ104KV-F[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][TABLE="width: 188"]
<tbody>[TR]
[TD="width: 188"]TDK[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 119"]
<tbody>[TR]
[TD="width: 119"]C1005X5R1E104K[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 100"]
<tbody>[TR]
[TD="width: 100"]437-123-01-00[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD]8[/TD]
[TD][TABLE="width: 31"]
<tbody>[TR]
[TD="width: 31"]EA[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 216"]
<tbody>[TR]
[TD="width: 216"]RES,10.0K,1%,0806[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][TABLE="width: 188"]
<tbody>[TR]
[TD="width: 188"]YAGEO[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 119"]
<tbody>[TR]
[TD="width: 119"]RC0402FR-0710KL[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][TABLE="width: 188"]
<tbody>[TR]
[TD="width: 188"]STACKPOLE ELECTRONIC INC.[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 119"]
<tbody>[TR]
[TD="width: 119"]RMCF0402FT10K0[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][TABLE="width: 188"]
<tbody>[TR]
[TD="width: 188"]Panasonic-ECG[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 119"]
<tbody>[TR]
[TD="width: 119"]ERJ-2RKF1002X[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

So that it ends up looking like the table below:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Component P/N[/TD]
[TD]Rev[/TD]
[TD]Qty[/TD]
[TD]BUn[/TD]
[TD]Description[/TD]
[TD]MFR1[/TD]
[TD]MPN1[/TD]
[TD]MFR2[/TD]
[TD]MPN2[/TD]
[TD]MFR3[/TD]
[TD]MPN3[/TD]
[/TR]
[TR]
[TD]130-158-01-02[/TD]
[TD]D2[/TD]
[TD]1[/TD]
[TD]EA[/TD]
[TD]Display/System uP,Jabron[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 100"]
<tbody>[TR]
[TD="width: 100"]220-819-01-00[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]G3[/TD]
[TD]1[/TD]
[TD]EA[/TD]
[TD]PCBA,System Contlr,Jabroni[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]402-745-01-00[/TD]
[TD][/TD]
[TD]23[/TD]
[TD]EA[/TD]
[TD]CAP,X5R,123FG,26V,9%,0806[/TD]
[TD][TABLE="width: 84"]
<tbody>[TR]
[TD="width: 84"]Taiyo-Yuden[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 119"]
<tbody>[TR]
[TD="width: 119"]TMK105BJ104KV-F[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 188"]
<tbody>[TR]
[TD="width: 188"]TDK[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 114"]
<tbody>[TR]
[TD="width: 114"]C1005X5R1E104K[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]437-123-01-00[/TD]
[TD][/TD]
[TD]8[/TD]
[TD]EA[/TD]
[TD]RES,10.0K,1%,0806[/TD]
[TD][TABLE="width: 84"]
<tbody>[TR]
[TD="width: 84"]YAGEO[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 119"]
<tbody>[TR]
[TD="width: 119"]RC0402FR-0710KL[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 188"]
<tbody>[TR]
[TD="width: 188"]STACKPOLE ELECTRONIC INC.[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 114"]
<tbody>[TR]
[TD="width: 114"]RMCF0402FT10K0[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 99"]
<tbody>[TR]
[TD="width: 99"]Panasonic-ECG[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 99"]
<tbody>[TR]
[TD="width: 99"]ERJ-2RKF1002X[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

This sample is much smaller than the actual data I am working with. the MFR & MPN can be as high as MFR36, MPN36 and can be over 1000 rows. Any help is much appreciated. Thanks!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this :-
Results on sheet2
Code:
[COLOR="Navy"]Sub[/COLOR] MG06Oct12
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Rw [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] R [COLOR="Navy"]As[/COLOR] Range, Temp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Q [COLOR="Navy"]As[/COLOR] Variant, oMax [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] R = Columns("A:G").Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious, LookAt:=xlPart)
[COLOR="Navy"]If[/COLOR] Not R [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
    Ray = ActiveSheet.Range("A1").Resize(R.Row, 7)
        ReDim nRay(1 To UBound(Ray, 1), 1 To UBound(Ray, 2))
            [COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
                .CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] Rw = 1 To UBound(Ray, 1)
 [COLOR="Navy"]If[/COLOR] Ray(Rw, 1) = "" [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] Ray(Rw, 6) <> "" [COLOR="Navy"]Then[/COLOR] Ray(Rw, 1) = Temp
 [COLOR="Navy"]End[/COLOR] If
 [COLOR="Navy"]If[/COLOR] Not Ray(Rw, 1) = "" [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] Not .Exists(Ray(Rw, 1)) [COLOR="Navy"]Then[/COLOR]
               n = n + 1
                [COLOR="Navy"]For[/COLOR] Ac = 1 To UBound(Ray, 2)
                    nRay(n, Ac) = Ray(Rw, Ac)
                [COLOR="Navy"]Next[/COLOR] Ac
            .Add Ray(Rw, 1), Array(n, 5)
        [COLOR="Navy"]Else[/COLOR]
          Q = .Item(Ray(Rw, 1))
            [COLOR="Navy"]For[/COLOR] Ac = 6 To UBound(Ray, 2)
                Q(1) = Q(1) + 1
                oMax = Application.Max(oMax, Q(1))
                [COLOR="Navy"]If[/COLOR] UBound(Ray, 2) < Q(1) [COLOR="Navy"]Then[/COLOR] ReDim Preserve nRay(1 To UBound(Ray, 1), 1 To oMax)
                nRay(1, Q(1)) = IIf(Q(1) Mod 2 = 0, "Mfg Name", "Mfr Part Number")
                nRay(Q(0), Q(1)) = Ray(Rw, Ac)
            [COLOR="Navy"]Next[/COLOR] Ac
        .Item(Ray(Rw, 1)) = Q
    [COLOR="Navy"]End[/COLOR] If
  Temp = Ray(Rw, 1)
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Rw
[COLOR="Navy"]End[/COLOR] With


[COLOR="Navy"]With[/COLOR] Sheets("Sheet2").Range("A1").Resize(n, UBound(nRay, 2))
    .Value = nRay
    .Columns.AutoFit
    .Borders.Weight = 2
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thanks MickG, this came really close to doing the trick. There were a couple issues though:


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Component P/N[/TD]
[TD]Rev[/TD]
[TD]Qty[/TD]
[TD]BUn[/TD]
[TD]Description[/TD]
[TD]MFG1[/TD]
[TD]MPN1[/TD]
[TD]MFG2[/TD]
[TD]MPN2[/TD]
[TD]MFG3[/TD]
[TD]MPN3[/TD]
[/TR]
[TR]
[TD][TABLE="width: 104"]
<tbody>[TR]
[TD="class: xl63, width: 104"]447-325-01-00[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Z3[/TD]
[TD]4[/TD]
[TD]EA[/TD]
[TD][TABLE="width: 321"]
<tbody>[TR]
[TD="class: xl65, width: 321"]XDCR,CUR,4.9V,+/-25A,T/H[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 263"]
<tbody>[TR]
[TD="class: xl66, width: 263"]SAMUELS[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 172"]
<tbody>[TR]
[TD="class: xl66, width: 172"]AFG6975-050B-VFR-T[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][TABLE="width: 263"]
<tbody>[TR]
[TD="class: xl66, width: 263"]SAMUELS[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 172"]
<tbody>[TR]
[TD="class: xl66, width: 172"]AFG6975-050B-VFR-T[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 104"]
<tbody>[TR]
[TD="class: xl65, width: 104"]395-875-01-00[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD]1[/TD]
[TD]EA[/TD]
[TD][TABLE="width: 321"]
<tbody>[TR]
[TD="class: xl65, width: 321"]CAP,FILM,1.5uF,250VAC,10%,RDL[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 263"]
<tbody>[TR]
[TD="class: xl66, width: 263"]TDR[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 172"]
<tbody>[TR]
[TD="class: xl66, width: 172"]CGL15-22VCR/TR6[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 263"]
<tbody>[TR]
[TD="class: xl66, width: 263"]PANATRONIC[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 172"]
<tbody>[TR]
[TD="class: xl66, width: 172"]ETGF-1TNF12L0U[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 263"]
<tbody>[TR]
[TD="class: xl66, width: 263"]SAMS[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 172"]
<tbody>[TR]
[TD="class: xl66, width: 172"]STF1224-470M[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

There is many cases like line 2 from the example above where the data from the MFG1 & MPN1 columns get copied over to MFG3/MPN3, MFG5/MPN5, etc.
 
Upvote 0
The problem I have is when I download your data the results contain a lot of merged cells and empty rows, as you say there are no merged cells I have removed them, but there is obvioulsy still a problem, if you could send you file or an Example of it via "Box.com" or similar i think we could resolve the problem !!!!
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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