如何在循环中创建连接 [英] how to create concatenation do while loop
问题描述
我有一个关于如何获取2列不同长度的问题并创建一个串联宏,它将所有内容组合成1个输出,步进A列并将A2与B2,B3,B4连接,然后将A3连接到
B2,B3,B4和等等。 感谢您提前获得任何帮助。
I have a question about how to take 2 columns of different lengths and create a concatenation macro that combines everything into 1 output by stepping through column A and concatenating A2 with B2, B3, B4, and then A3 with
B2, B3, B4 an so on. Thanks for any help in advance.
推荐答案
在这里:
Sub CreateCombinations()
Dim r As Long
Dim m As Long
Dim s As Long
Dim n As Long
Dim t As Long
Application.Cursor = xlWait
Application.ScreenUpdating = False
m =范围("A"& Rows.Count).End(xlUp).Row
n =范围("B"& Rows.Count).End(xlUp).Row
t = 1
对于r = 2 To m
对于s = 2到n $
t = t + 1
范围("D"& t).Value =范围("A"& r).Value&范围("B"& s).Value
下一个s
下一个r
Application.ScreenUpdating = True
Application.Cursor = xlDefault
End Sub
Sub CreateCombinations()
Dim r As Long
Dim m As Long
Dim s As Long
Dim n As Long
Dim t As Long
Application.Cursor = xlWait
Application.ScreenUpdating = False
m = Range("A" & Rows.Count).End(xlUp).Row
n = Range("B" & Rows.Count).End(xlUp).Row
t = 1
For r = 2 To m
For s = 2 To n
t = t + 1
Range("D" & t).Value = Range("A" & r).Value & Range("B" & s).Value
Next s
Next r
Application.ScreenUpdating = True
Application.Cursor = xlDefault
End Sub
这篇关于如何在循环中创建连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!