将某行数据移动到列中(反转现有宏)

时间:2012-07-10 11:22:48

标签: excel vba excel-vba

此处提供的解决方案参考: https://stackoverflow.com/a/9231458

我需要反过来做,例如:

A E F G H I
B J K L M N
C O P Q R S
D T U V W X

A E
A F
A G
A H
A I
B J
B K
B L
B M
B N
C O
C P
C Q
C R
C S
D T
D U
D V
D W
D X

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:2)

Sheet

Sub foo()

    Dim rng As Range
    Dim row As Integer
    Dim col As Integer

    Set rng = Sheets("Sheet1").Range("A1:A4")
    row = 0

    For Each cell In rng
        col = 1
        Do Until cell.Offset(0, col) = ""
            Sheets("Sheet1").Range("A6").Offset(row, 0) = cell
            Sheets("Sheet1").Range("A6").Offset(row, 1) = cell.Offset(0, col)
            row = row + 1
            col = col + 1
        Loop
    Next cell


End Sub