Taking a list that fills multiple columns and turn it into a list with only 2 columns

mcfurlong1

New Member
Joined
Mar 19, 2020
Messages
3
I currently have a list of clients where in some cases, the clients have multiple client numbers which are in different columns. I need to move those with multiple client numbers to have the client number on it's own row. My dataset currently looks like this:

CLIENTCODE 1CODE 2CODE 3CODE 4
Alina Smith
1​
5​
9​
12​
Ashley Ray
3​
6​
Ben Goldsmith
2​
Bill Luther
8​
Brett Beavers
7​
4​

And I want it to look like this:
CLIENTCODE
Alina Smith
1​
Alina Smith
5​
Alina Smith
9​
Ashley Ray
3​
Ashley Ray
6​
Ben Goldsmith
2​
Bill Luther
8​
Brett Beavers
7​
Brett Beavers
4​
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi & welcome to MrExcel.
How about
VBA Code:
Sub mcfurlong1()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, rr As Long
   
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To UBound(Ary) * UBound(Ary, 2), 1 To 2)
   rr = 1
   Nary(rr, 1) = "Client"
   Nary(rr, 2) = "Code"
   For r = 2 To UBound(Ary)
      For c = 2 To UBound(Ary, 2)
         If Ary(r, c) <> "" Then
            rr = rr + 1
            Nary(rr, 1) = Ary(r, 1)
            Nary(rr, 2) = Ary(r, c)
         End If
      Next c
   Next r
   Sheets("Sheet2").Range("A1").Resize(rr, 2).Value = Nary
End Sub
Change sheet names to suit
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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