有没有可以将A的所有列合并到B的所有列的功能

时间:2019-06-19 08:24:12

标签: excel excel-formula concatenation textjoin

我在Excel中遇到一种情况,我想将A列的所有值组合到B列的所有值(在这里我想将B的所有值都绝对保留为A列的所有值)

示例: 列A-1 2 3 4 5 6 7 8 B栏-A B C D E F G H

我想要的结果是 1A 2A 3A 4A 5A 6A 7A 8A 1B 2B 3B 4B 5B直到我达到8H

我尝试了简单的串联,但是显然耗时太长

如果有人可以调查一下并为我提供一个公式来帮助解决此问题,将不胜感激。

致谢

2 个答案:

答案 0 :(得分:1)

发布您的信息后,我意识到您的真正追求。

在单元格C1中放置:

=IF(ROW()-ROW($C$1)+1>COUNTA(A:A)*COUNTA(B:B),"",INDEX(A:A,INT((ROW()-ROW($C$1))/COUNTA(B:B)+1))&INDEX(B:B,MOD(ROW()-ROW($C$1),COUNTA(B:B))+1))

然后向下拖动

enter image description here

答案 1 :(得分:0)

我找到了这种解决方案,但是在VBA中。希望对你没事。 That's how it look on my excel

Sub Merge()

Dim NumberLeng As Range
Dim LetterLeng As Range
Dim LastLetter As Long
Dim LastNumber As Long
Dim sht As Worksheet
Dim LastRow As Long
Dim LastMix As Long
Set sht = ActiveSheet
LastLetter = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row 'last letter
LastNumber = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row 'last number

Set NumberRange = sht.Range(Cells(1, 1), Cells(LastNumber, 1)) ' range of numbers
Set LetterRange = sht.Range(Cells(1, 2), Cells(LastLetter, 2)) ' range of letters
X = 0
    For Each Letter In LetterRange

        For Each Number In NumberRange

        Number.Offset(X, 2) = Number & Letter 'Number+Letter

        Next Number

    LastMix = sht.Cells(sht.Rows.Count, "C").End(xlUp).Row 'set new last
    X = LastMix

    Next Letter

End Sub

如果需要帮助,请询问:)