使用相同的参数多次调用Sub

时间:2018-04-11 13:20:20

标签: excel vba excel-vba

我正在尝试调整多个工作表中的多个列。出于某种原因,只有第一个起作用。是因为我正在改变这两个变量吗?

    Set targetSh = owb.Sheets("INPUT_INSTRUMENT")

    Set resizeSh = owb.Sheets("Info")
    tablename = "Table5"
    Call RowsAction(targetSh, resizeSh, tablename)

    Set resizeSh = owb.Sheets("Review")
    tablename = "Table17"
    Call RowsAction(targetSh, resizeSh, tablename)


Sub RowsAction(ByRef targetSh As Worksheet, resizeSh As Worksheet, tablename As String)
    Dim i, iLastRow As Integer, oLastRow As ListRow, srcRow As Range

    Last = targetSh.Range("A1", targetSh.Cells(Rows.count, "A").End(xlUp)).count - 2

    For i = 1 To Last
        Set srcRow = resizeSh.ListObjects(tablename).ListRows(i).Range
        Set oLastRow = resizeSh.ListObjects(tablename).ListRows.Add
        srcRow.Copy
        oLastRow.Range.PasteSpecial
        Application.CutCopyMode = False
    Next
End Sub

0 个答案:

没有答案