Excel: moving data from multiple columns to a 2-column format
August 17, 2006 5:00 AM
Subscribe
Excel / VBA help needed: moving data from multiple columns to a 2-column format
I've got an Excel worksheet which contains data in the following format:
Foo 1 3 7
Bar 3 5
Yay 1 5 11 17
And I need it in this format:
Foo 1
Foo 3
Foo 7
Bar 3
Bar 5
Yay 1
Yay 5
Yay 11
Yay 17
...where the contents of columns B:ZZ are moved to B1:B999 and the relevant title from column A is listed alongside each item. It's complicated by the fact that each title has a variable number of entries alongside it: some have as many as 30, some have none.
I know the 'transpose' command will convert the rows to columns but it's still not what I'm after. It may be the first step, though.
Is there an easy way to do this automagically or is it a VB task? If so, any VB geniuses out there?
Thanks
posted by blag to computers & internet (9 comments total)
(oh.. well, so much for indenting....)
----
' ***********************************************************************************
' * presuming this all starts at A1, the existing data is in a sheet called "input" *
' * and the results go into an existing sheet called "results" *
' ***********************************************************************************
range("a1").activate
while activecell.value <> ""
n=1
label = activecell.value
while selection.offset(0,n) <> ""
item = selection.offset(0,n)
sheets("results").activate
activecell.value = label
selection.offset(0,1).value = item
selection.offset(1,0).select
sheets("input").activate
n=n+1
wend
selection.offset(1,0).select
wend>>
posted by pompomtom at 5:49 AM on August 17, 2006