在Excel中配对单元格

我有两个不同的值在Excel中的列:

A 1 B 2 C 3 

现在,我需要将第一列的每个单元格与第二列的每个单元格进行配对。 所以它看起来像这样:

 A 1 A 2 A 3 B 1 B 2 B 3 C 1 C 2 C 3 

你知道我怎么能这样做吗?

谢谢你堆

使用列AB中的数据来尝试这个简短的macros:

 Sub MakeCombinations() Dim Na As Long, Nb As Long Dim i As Long, j As Long, K As Long Dim rc As Long K = 1 rc = Rows.Count Na = Cells(rc, 1).End(xlUp).Row Nb = Cells(rc, 2).End(xlUp).Row For i = 1 To Na For j = 1 To Nb Cells(K, 3) = Cells(i, 1) Cells(K, 4) = Cells(j, 2) K = K + 1 Next j Next i End Sub 

在这里输入图像说明

编辑#1:

在没有VBA的情况下 ,在C1中input:

 =INDEX(A:A,ROUNDUP(ROW()/COUNTA(B:B),0),1) 

并复制并在D1中input:

 =INDEX(B:B,MOD(ROW()-1,COUNTA(B:B))+1,1) 

并抄下来:

在这里输入图像说明

我用数组修改Gary的答案。 没有testing,由于我的Mac没有Excel。

 Sub MakeCombinations() Dim Ary_a As Variant, Ary_b As Variant, Ary as Variant Dim i As Long, j As Long Ary_a = range(Cells(rows.count, 1).End(xlUp).Row, 1).value Ary_b = range(Cells(rows.count, 2).End(xlUp).Row, 2).value For i = lbound(ary_a) To ubound(ary_a) For j = lbound(ary_b) To ubound(ary_b) if not isarray(ary) then redim ary(1, 0) else redim preserve ary(1, ubound(ary, 2)+1) end if ary(0, ubound(ary, 2)) = ary_a(i) ary(1, ubound(ary, 2)) = ary_b(j) Next j Next i cells(1, 4).resize(ubound(ary, 2)+1, ubound(ary, 1)+1).value = application.transpose(ary) End Sub