Combine 2 Columns of Different Lengths for More than 1 set of Data in Excel

KeKemp

New Member
Joined
Nov 10, 2015
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am new to posting so I apologize if this is written incorrectly or confusing.

I am looking for a formula or Macro that will allow me to combine 2 columns of different lengths. If it is a Macro I need it to be able to run based on a different cell each time.

So if I use the example data below I am trying to get a new column for Data Set 1 that has:

A1
A2
A3
B1
B2
B3 (etc.)

However, then I want to use the same method toward Data Set 2 even though it has different column lengths an will not be in the same location on a sheet as Data Set 1

Example:
Data Set 1Data Set 2
ProgramLocationProgramLocation
A
1​
A
1​
B
2​
B
2​
C
3​
C
3​
DD
4​
EE
5​
FF
6​
GG
HH
I
J
K

Thank you.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
The macro will create list in the 3rd column (to the right of Location column).
How to use:
Select anchor cell which is A in Program column. Alt+F8 and run macro
VBA Code:
Sub CombineList()

Dim n As Long, m As Long
Dim cell_Prog As Range, rngProg As Range
Dim cell_Loc As Range, rngLoc As Range

n = ActiveCell.Row
m = ActiveCell.Offset(, 2).Column

Set rngProg = Range(ActiveCell, ActiveCell.End(xlDown))
Set rngLoc = Range(ActiveCell.Offset(, 1), ActiveCell.Offset(, 1).End(xlDown))

For Each cell_Prog In rngProg
    For Each cell_Loc In rngLoc
        Cells(n, m) = cell_Prog & cell_Loc
        n = n + 1
    Next
Next

End Sub
 
Upvote 0
Solution
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
I have added this information to my profile Thank you.
 
Upvote 0
The macro will create list in the 3rd column (to the right of Location column).
How to use:
Select anchor cell which is A in Program column. Alt+F8 and run macro
VBA Code:
Sub CombineList()

Dim n As Long, m As Long
Dim cell_Prog As Range, rngProg As Range
Dim cell_Loc As Range, rngLoc As Range

n = ActiveCell.Row
m = ActiveCell.Offset(, 2).Column

Set rngProg = Range(ActiveCell, ActiveCell.End(xlDown))
Set rngLoc = Range(ActiveCell.Offset(, 1), ActiveCell.Offset(, 1).End(xlDown))

For Each cell_Prog In rngProg
    For Each cell_Loc In rngLoc
        Cells(n, m) = cell_Prog & cell_Loc
        n = n + 1
    Next
Next

End Sub
This was exactly what I was looking for! Thank you!
 
Upvote 0
Thanks for that, with a formula
+Fluff 1.xlsm
ABCDEFGHI
1Data Set 1Data Set 2
2ProgramLocationProgramLocation
3A1A1AA
4B2B2BB
5C3C3CC
6DD4DD
7EE5EE
8FF6FF
9GGGG
10HHHH
11I1I
12J2J
13K3K
141
152
163
174
185
196
Main
Cell Formulas
RangeFormula
H3:H13H3=LET(Rng,A3:B10,r,ROWS(Rng),s,SEQUENCE(r*COLUMNS(Rng),,0),a,INDEX(Rng, MOD(s,r)+1,INT(s/r)+1),FILTER(a,a<>""))
I3:I19I3=LET(Rng,D3:E13,r,ROWS(Rng),s,SEQUENCE(r*COLUMNS(Rng),,0),a,INDEX(Rng, MOD(s,r)+1,INT(s/r)+1),FILTER(a,a<>""))
Dynamic array formulas.


Then all you need to do is change the range in the variable Rng for any data set
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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