需要有人可以阅读这个VBA脚本!相当简单

时间:2016-09-19 22:58:09

标签: excel vba list

Public Sub MakeColumnsFromRows()
    Dim totalCutsToMake As Integer
    Dim currentColumn As Integer
    Dim currentCut As Integer
    Dim rowsToCut As Integer

    Sheets(1).Activate
    rowsToSkip = 10
    totalCutsToMake = (ActiveSheet.UsedRange.Rows.Count / rowsToSkip)
    currentColumn = 1

    Dim RowCount As Integer
    For currentCut = 1 To totalCutsToMake
        RowCount = Cells(Rows.Count, currentColumn).End(xlUp).Row
        Range(Cells(rowsToSkip + 1, currentColumn), Cells(RowCount, currentColumn + 1)).Select
        Selection.Cut
        Cells(1, currentColumn + 2).Select
        ActiveSheet.Paste
        currentColumn = currentColumn + 2
    Next
End Sub

这是我的VBA脚本,它会在前两列中每10行剪切一次,然后将它们粘贴到下一列中。 (将500行的列表缩短为50行10行等)

我需要什么: 我接下来没有VBA的经验,我只是想编辑这个脚本来选择&削减前3列而不是当前削减的2列。对于能够轻松阅读脚本的人来说,这应该非常简单。我可以看到它在'Range'部分,但是我没有花时间去学习改变它的语法。

如果可能,编辑VBA脚本以剪切前3列的前10行,然后粘贴到接下来的3列中并重复。

请告诉我对该系列的编辑。

1 个答案:

答案 0 :(得分:-1)

Public Sub MakeColumnsFromRows()
    Dim totalCutsToMake As Integer
    Dim currentColumn As Integer
    Dim currentCut As Integer
    Dim rowsToCut As Integer

    Sheets(4).Activate
    rowsToSkip = 10
    totalCutsToMake = (ActiveSheet.UsedRange.Rows.Count / rowsToSkip)
    currentColumn = 1

    Dim RowCount As Integer
    For currentCut = 1 To totalCutsToMake
        RowCount = Cells(Rows.Count, currentColumn).End(xlUp).Row
        Range(Cells(rowsToSkip + 1, currentColumn), Cells(RowCount, currentColumn + 2)).Select
        Selection.Cut
        Cells(1, currentColumn + 3).Select
        ActiveSheet.Paste
        currentColumn = currentColumn + 3
    Next
End Sub