根据指定的数量将行中的数据移出x列

时间:2016-06-28 21:34:49

标签: excel excel-vba vba

我需要将所有数据连续移出:

AAPL
AAWW
BBRY
ZGSI

我有很多行,它们甚至可以跨越几百列......因此有所帮助。感谢

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题你需要:

Sub ShiftData()
  Dim ActiveRow As Range
  Dim InputData As Range

  Set InputData = Range(Range("A2"), Range("A2").End(xlDown))

  For Each ActiveRow In InputData.Rows
    'Paste contents starting column C(3)
    Cells(ActiveRow.Row, 3 + ActiveRow.Offset(0, 1).Value + 0).Value = ActiveRow.Value
    Cells(ActiveRow.Row, 3 + ActiveRow.Offset(0, 1).Value + 1).Value = ActiveRow.Value
    Cells(ActiveRow.Row, 3 + ActiveRow.Offset(0, 1).Value + 2).Value = ActiveRow.Value
  Next
End Sub