Excel VBA-拆分数据并转置粘贴

时间:2018-10-03 14:04:03

标签: excel vba excel-vba

有。我是vba的新手,我正在尝试编写一个vba函数,该函数可以拆分数据并将其复制并转置并将其粘贴到另一张工作表中。有人可以帮我吗?

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

您可以拆分为一个数组,然后转置该数组并使用直接值传递。

sub qwerty()

    dim i as long, arr as variant, ws as worksheet

    set ws = worksheets("sheet2")

    with worksheets("sheet1")
        for i=1 to .cells(.rows.count, "A").end(xlup).row
            arr = split(.cells(i, "A").value2, "|")
            ws.cells(1, i).resize(ubound(arr)+1, 1) = application.transpose(arr)
        next i
    end with

end sub