Transposing data SETS from vertical to horizontal

tutuzdad

New Member
Joined
Mar 16, 2015
Messages
14
I desperately need to transpose multiple SETS of data so that the now vertical columns are horizontal. I know about transposing but not when it comes to sets. For simplicity sake let’s say I have a long list of multiple addresses with the headers, NAME, ADDR, CITY, STATE, ZIP. Transposing these headers into a horizontal table is fairly simple. It’s getting the 5 rows of names, addresses, cities, states and zips under the correct headers that has me confounded. I’m using 2010. I’m pretty familiar with excel. Ideally a solution that I can reapply to future lists since this is something I do regularly and my output is always formatted this same annoying way. I don’t do VB but if we have to and you can simply it step-by-step for me I’d really appreciate it.
 
tutuzdad, New sample raw data in worksheet Sheet1 (you can change the raw data worksheet name in the macro): Excel 2007
ABC
1A1
2B2
3C3
4D4
5E5
6F6
7G7
8H8
9I9
10J10
11K11
12L12
13M13
14N14
15O15
16P16
17Q17
18R18
19S19
20A20
21B21
22C22
23D23
24E24
25F25
26G26
27H27
28I28
29J29
30K30
31L31
32M32
33N33
34O34
35P35
36Q36
37R37
38S38
39A39
40B40
41C41
42D42
43E43
44F44
45G45
46H46
47I47
48J48
49K49
50L50
51M51
52N52
53O53
54P54
55Q55
56R56
57S57
58

<colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

After the macro (using two arrays in memory) in a new worksheet Results: Excel 2007
ABCDEFGHIJKLMNOPQRST
1ABCDEFGHIJKLMNOPQRS
212345678910111213141516171819
320212223242526272829303132333435363738
439404142434445464748495051525354555657
5

<colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead>
</thead><tbody>
</tbody>
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).
Code:
  Sub TransposeData_V3() ' hiker95, 03/18/2015, ME842652 Dim w1 As Worksheet, wr As Worksheet Dim a As Variant, o As Variant Dim i As Long, j As Long Application.ScreenUpdating = False Set w1 = Sheets("Sheet1")   ''<-- change the raw data worksheet name here a = w1.Cells(1, 1).CurrentRegion ReDim o(1 To UBound(a, 1) / 19, 1 To 19) For i = 1 To UBound(a, 1) Step 19   j = j + 1   o(j, 1) = a(i, 2)   o(j, 2) = a(i + 1, 2)   o(j, 3) = a(i + 2, 2)   o(j, 4) = a(i + 3, 2)   o(j, 5) = a(i + 4, 2)   o(j, 6) = a(i + 5, 2)   o(j, 7) = a(i + 6, 2)   o(j, 8) = a(i + 7, 2)   o(j, 9) = a(i + 8, 2)   o(j, 10) = a(i + 9, 2)   o(j, 11) = a(i + 10, 2)   o(j, 12) = a(i + 11, 2)   o(j, 13) = a(i + 12, 2)   o(j, 14) = a(i + 13, 2)   o(j, 15) = a(i + 14, 2)   o(j, 16) = a(i + 15, 2)   o(j, 17) = a(i + 16, 2)   o(j, 18) = a(i + 17, 2)   o(j, 19) = a(i + 18, 2) Next i If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results" Set wr = Sheets("Results") With wr   .UsedRange.Clear   .Cells(1, 1).Resize(, 19).Value = Application.Transpose(w1.Range("A1:A19"))   .Cells(2, 1).Resize(UBound(o, 1), UBound(o, 2)) = o   .Columns(1).Resize(, UBound(o, 2)).AutoFit   .Activate End With Application.ScreenUpdating = True End Sub
Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook. Then run the TransposeData_V3 macro.
Thank you. I envy your command of Excel. You are unquestionably a world class pro. Just FYI - I don't know how often (if ever) you hear "the rest of the story", but in solving this problem you have unknowingly provided a very important service to more than 1,000,000 people. Transposing the data so that it is formatted in this way essentially "translates it" and makes it possible for a public safety entity to feed it to analysis software, which will, in turn, analyze the data and help make the community a much safer place to live and play. The solution that you provided is the final key to a public safety project that began some 14 months ago and in about 15 minutes we will stick the key in the ignition and take the project out for it's first test drive. I just thought you might like to know the measure of the impact your involvement and selfless contribution has had on so many. You have my gratitude on their behalf. In an attempt to proactively prepare for whatever glitches might arise, at some point I might like to ask you if there is a way to ensure that the raw data is bound to it's corresponding header. For example, in the rare instance that some of the sets are NOT 19 rows long and happen to be only 17 or 18 rows long (which is somewhat rare and when it happens that line is not blank, but missing entirely (row, data, header and all) is there a way to transpose the data as you have done, but guarantee that the movement is contingent upon it's corresponding header - REGARDLESS of what row it is on. Put another way perhaps, how might we transpose this data and achieve the same end result if the sets were not consistently in the same order. [They are typically ordered 1,2, 3, 4, 6... but one or more of them happened to be 1, 2, 4, 5, 6... and another happened to be 1, 3, 4, 2, 6, 5... This may be something that requires some thought, but in the meantime let me say again how deeply appreciattive we are for your services rendered. Thank you so much.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
tutuzdad,

Thanks for the feedback.

You are very welcome. Glad I could help.


Unless there is a particular reason to do so, it is best not to quote whole long posts like you did with mine. It makes the thread harder to navigate/read and just takes up unnecessary space.

1. Quote ONLY if it is needed to add clarity or context for your reply. If so, then
2. Quote ONLY the specific part of the post that is relevant - - not the entire post.

This will keep thread clutter to a minimum and make the discussion easier to follow.

And, when you respond to your helper, please use their site ID/username/handle.


For example, in the rare instance that some of the sets are NOT 19 rows long and happen to be only 17 or 18 rows long (which is somewhat rare and when it happens that line is not blank, but missing entirely (row, data, header and all) is there a way to transpose the data as you have done, but guarantee that the movement is contingent upon it's corresponding header - REGARDLESS of what row it is on. Put another way perhaps, how might we transpose this data and achieve the same end result if the sets were not consistently in the same order. [They are typically ordered 1,2, 3, 4, 6... but one or more of them happened to be 1, 2, 4, 5, 6... and another happened to be 1, 3, 4, 2, 6, 5...

In order to continue I will have to see your actual NEW raw data structure, and, results (manually formatted by you) for the results you are looking for.

You will have to find a way, maybe on another computer outside of work, to post your actual NEW raw data structure, and, results (manually formatted by you) for the results you are looking for.

You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.


If you can not provide the above, then:

Click on the Reply to Thread button, and just put the word BUMP in the thread. Then, click on the Post Quick Reply button, and someone else will assist you.
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,069
Members
449,090
Latest member
fragment

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