Macro For Transpose Paste Into New Rows (Modified Example) to modify a VBA code.

Biggy

New Member
Joined
Feb 14, 2014
Messages
22
Hello,

Thank You all for Your huge help solving lot of issues and helping out.

My first example with this issue was in the post here. I got two response for fixing this issue. I thought about how to change code into 1st of the answers (given by Rick) to make it work for situation stated below, but couldn't - it moved data around, didn't copied some of the information, etc. Ok, I could get it work then it shows newly added item# and also more sizes, but data it copied after, e.g. name and color wasn't in the right places and some other issues. Maybe someone could give me an explanation how to modify it and what means what in the code so in the future I can modify it by myself depending on situation? Below are new situation:

Before
ABCDEFGHIJKLMNOP
1Item#NameColor8101214161820222426Price
2TSH100T-ShirtWhiteN$10,
3TSH101T-ShirtBlack$14,
4
5Item#NameColorMLXLXXL3XL4XLPrice
6PLSH100Polo ShirtYellowN$12,
7PLSH101Polo ShirtOrangeN$12,
8PLSH102Polo ShirtBlack$15,

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet3



After
ABCDEF
11Item#NameColorSizeAvailablePrice
12TSH100T-ShirtWhite8$10,
13TSH100T-ShirtWhite10$10,
14TSH100T-ShirtWhite12$10,
15TSH100T-ShirtWhite14N$10,
16TSH100T-ShirtWhite16$10,
17TSH100T-ShirtWhite18$10,
18TSH100T-ShirtWhite20$10,
19TSH100T-ShirtWhite22$10,
20TSH100T-ShirtWhite24$10,
21TSH100T-ShirtWhite26$10,
22TSH101T-ShirtBlack8$14,
23TSH101T-ShirtBlack10$14,
24TSH101T-ShirtBlack12$14,
25TSH101T-ShirtBlack14$14,
26TSH101T-ShirtBlack16$14,
27TSH101T-ShirtBlack18$14,
28TSH101T-ShirtBlack20$14,
29TSH101T-ShirtBlack22$14,
30TSH101T-ShirtBlack24$14,
31TSH101T-ShirtBlack26$14,
32
33
34Item#NameColorSizeAvailablePrice
35PLSH100Polo ShirtYellowMN$14,
36PLSH100Polo ShirtYellowL$14,
37PLSH100Polo ShirtYellowXL$14,
38PLSH100Polo ShirtYellowXXL$14,
39PLSH100Polo ShirtYellow3XL$14,
40PLSH100Polo ShirtYellow4XL$14,
41PLSH101Polo ShirtOrangeM$14,
42PLSH101Polo ShirtOrangeL$14,
43PLSH101Polo ShirtOrangeXLN$14,
44PLSH101Polo ShirtOrangeXXL$14,
45PLSH101Polo ShirtOrange3XL$14,
46PLSH101Polo ShirtOrange4XL$14,
47PLSH102Polo ShirtBlackM$15,
48PLSH102Polo ShirtBlackL$15,
49PLSH102Polo ShirtBlackXL$15,
50PLSH102Polo ShirtBlackXXL$15,
51PLSH102Polo ShirtBlack3XL$15,
52PLSH102Polo ShirtBlack4XL$15,

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet3

Here are code which was made by a Rick for situation then There wasn't Item # , so in Column A was a "name", but sizes went till Column L. Hopefully someone will be able to help me with this one.

Code:
Sub TransposeSizeTable()
  Dim X As Long, Cnt As Long, LastRow As Long, NewStart As Long, Ar As Range
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  NewStart = LastRow + 5
  For Each Ar In Range("A1:A" & LastRow).SpecialCells(xlConstants).Areas
    Cells(NewStart, "A").Resize(, 5) = Array("Name", "Color", "Size", "Available", "Price")
    Cnt = Application.CountA(Ar(1).Offset(, 2).Resize(, 10))
    For X = 1 To Ar.Rows.Count - 1
      Cells(NewStart + X, "A").Resize(Cnt, 2).Value = Ar(1).Offset(X).Resize(, 2).Value
      Cells(NewStart + X, "C").Resize(Cnt) = Application.Transpose(Ar(1).Offset(, 12 - Cnt).Resize(, Cnt))
      Cells(NewStart + X, "E").Resize(Cnt).Value = Ar(1).Offset(X, 12).Value
      If X = 1 Then
        Cells(NewStart + X, "D").Resize(Cnt) = Application.Transpose(Ar(1).Offset(X, 12 - Cnt).Resize(, Cnt))
      Else
        Cells(NewStart + X, "D").Resize(Cnt) = Application.Transpose(Ar(1).Offset(X, 12 - Cnt).Resize(, Cnt))
      End If
      NewStart = NewStart + Cnt - 1
    Next
    NewStart = Cells(Rows.Count, "A").End(xlUp).Row + 3
  Next
End Sub

Sorry for bothering You all, but I really want to understand how it works. So Thank You for reading this!

Sincerely,
Biggy
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,614
Messages
6,125,848
Members
449,266
Latest member
davinroach

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