Convert from table to a list

alexwangsa

New Member
Joined
Sep 17, 2008
Messages
10
Hi,

I need to convert this kind of table to a list (like in below example)
Can someone give me an instruction or macro to do this ?

Table
X Y Z
A 3 5 7
B 2 4 6
C 8 9 10

List
Column1 Column2 Column3
A X 3
A Y 5
A Z 7
B X 2
B Y 4
B Z 6
C X 8
C Y 9
C Z 10

Thanks in advance,
Alex
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Oops
try
Rich (BB code):
Sub test()
Dim a, b(), i As Long, ii As Long, n As Long
a = Range("b6").CurrentRegion.Value
ReDim b(1 To UBound(a,1) * UBound(a,2), 1 To 3)
For ii = 2 To UBound(a,2)
    For i = 2 To UBound(a,1)
        If a(i, ii) <> "" Then
            n = n + 1
            b(n, 1) = a(i,1) : b(n, 2) = a(1, ii) : b(n, 3) = a(i,ii)
        End If
    Next
Next
Sheets("sheet2").Range("hh7").Resize(n,3).Value = b
End Sub
 
Upvote 0
Hi, you managed to exclude all the blank cells in the output. I have change the code in line 13. Range ("hh7") to ("A1") because that's where I want the output to start.

Almost there.

The issue is : first column of output contains description from A7 instead of B7 in the source.
 
Last edited:
Upvote 0
change
Code:
a = Range("b6").CurrentRegion.Value
to
Code:
With Range("b6").CurrentRegion
    a = .Resize(, .Columns.Count - 1).Offset(, 1).Value
End With
 
Upvote 0
You are welcome.

However, when I saw your sheet thought the link, I thought there was nothing in col.A, so that I just used Range("b6").CurrentRegion.

But the fact is you have something in Col.A.

I don't understand why you started from col.B, but it is always better start from Col.A for the later manipulation.
 
Upvote 0
I delete the contents of column A which is product description, because I only need product codes. Once I get the output, I am going to put them into microsoft access.
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,792
Members
449,126
Latest member
Greeshma Ravi

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