Excel VBA文本添加

时间:2018-05-23 18:51:44

标签: excel excel-vba vba

我正在尝试自动化我的代码,以便我可以从一个列表中提取某些字符并将它们添加到另一个列表的末尾。例如

opencv-contrib-python

我尝试过使用循环,在下面的代码中给出了一个结果,例如:oneabc,twoabc,threeabc。我在哪里错了?

List 1 ... one , two, three
List 2 .... a, b , c 
Result after clicking a button : onea, twob, threec 

1 个答案:

答案 0 :(得分:0)

仍然不是100%,但也许这会有所帮助:-p

Sub meme()

    Dim arr As Collection
        Set arr = New Collection

    Dim rng As Range
        Set rng = Sheets("Sheet1").Range("A1:A10")

    For Each cell In rng
        arr.Add (cell)
    Next cell

    Dim arrTwo As Collection
        Set arrTwo = New Collection

    Dim rngTwo As Range
        Set rngTwo = Sheets("Sheet1").Range("B1:B10")

    For Each cell In rngTwo
        arrTwo.Add (cell)
    Next cell

    Dim counter As Integer
        counter = 1

    For Each Item In arr
        Sheets("Sheet1").Cells(counter, 3) = Item & arrTwo(counter)
        counter = counter + 1
    Next Item
End Sub