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:

Component P/NRevQtyBUnDescriptionMfg NameMfr Part Number
130-158-01-02
D2

<tbody>
</tbody>
1
EA

<tbody>
</tbody>
Display/System uP,Jabroni

<tbody>
</tbody>
220-819-01-00

<tbody>
</tbody>
G3

<tbody>
</tbody>
1
EA

<tbody>
</tbody>
PCBA,System Contlr,Jabroni

<tbody>
</tbody>
402-745-01-00

<tbody>
</tbody>
23
EA

<tbody>
</tbody>
CAP,X5R,123FG,26V,9%,0806

<tbody>
</tbody>
Taiyo-Yuden

<tbody>
</tbody>
TMK105BJ104KV-F

<tbody>
</tbody>
TDK

<tbody>
</tbody>
C1005X5R1E104K

<tbody>
</tbody>
437-123-01-00

<tbody>
</tbody>
8
EA

<tbody>
</tbody>
RES,10.0K,1%,0806

<tbody>
</tbody>
YAGEO

<tbody>
</tbody>
RC0402FR-0710KL

<tbody>
</tbody>
STACKPOLE ELECTRONIC INC.

<tbody>
</tbody>
RMCF0402FT10K0

<tbody>
</tbody>
Panasonic-ECG

<tbody>
</tbody>
ERJ-2RKF1002X

<tbody>
</tbody>

<tbody>
</tbody>

So that it ends up looking like the table below:

Component P/NRevQtyBUnDescriptionMFR1MPN1MFR2MPN2MFR3MPN3
130-158-01-02D21EADisplay/System uP,Jabron
220-819-01-00

<tbody>
</tbody>
G31EAPCBA,System Contlr,Jabroni
402-745-01-0023EACAP,X5R,123FG,26V,9%,0806
Taiyo-Yuden

<tbody>
</tbody>
TMK105BJ104KV-F

<tbody>
</tbody>
TDK

<tbody>
</tbody>
C1005X5R1E104K

<tbody>
</tbody>
437-123-01-008EARES,10.0K,1%,0806
YAGEO

<tbody>
</tbody>
RC0402FR-0710KL

<tbody>
</tbody>
STACKPOLE ELECTRONIC INC.

<tbody>
</tbody>
RMCF0402FT10K0

<tbody>
</tbody>
Panasonic-ECG

<tbody>
</tbody>
ERJ-2RKF1002X

<tbody>
</tbody>

<tbody>
</tbody>

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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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:


Component P/NRevQtyBUnDescriptionMFG1MPN1MFG2MPN2MFG3MPN3
447-325-01-00

<tbody>
</tbody>
Z34EA
XDCR,CUR,4.9V,+/-25A,T/H

<tbody>
</tbody>
SAMUELS

<tbody>
</tbody>
AFG6975-050B-VFR-T

<tbody>
</tbody>
SAMUELS

<tbody>
</tbody>
AFG6975-050B-VFR-T

<tbody>
</tbody>
395-875-01-00

<tbody>
</tbody>
1EA
CAP,FILM,1.5uF,250VAC,10%,RDL

<tbody>
</tbody>
TDR

<tbody>
</tbody>
CGL15-22VCR/TR6

<tbody>
</tbody>
PANATRONIC

<tbody>
</tbody>
ETGF-1TNF12L0U

<tbody>
</tbody>
SAMS

<tbody>
</tbody>
STF1224-470M

<tbody>
</tbody>

<tbody>
</tbody>

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,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

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