VBA Listobjects单元格范围

时间:2016-08-29 20:47:33

标签: vba excel-vba excel

我正在尝试从VBA中的ListObject复制一系列单元格。我不需要整行的单元格,我只需要当前数据行中前两列的单元格。我使用" For"声明遍历表中的所有行。在下面的代码中,我注释了我需要代码的位置。

Sub ReportGenerate()
'
' Generates invoice for selected firm
'
    Dim wkb As Workbook
    Set wkb = Workbooks.Open("V:\Invoice template.xlsx")

    Dim crntwb As Workbook
    Set crntwb = ThisWorkbook

    Dim invoiceT As Excel.ListObject
    Set invoiceT = wkb.Worksheets("Sheet1").ListObjects("AppFee")

    Dim AppT As Excel.ListObject
    Set AppT = crntwb.Worksheets("App Fee Master List").ListObjects("AppFee")

    Dim Firm As String
    Firm = crntwb.Worksheets("App Fee Dashboard").Range("E6").Value

    wkb.Worksheets("Sheet1").Range("B7").Value = Firm

    'Start here for code regarding question
    LastRow = AppT.ListRows.Count

    For i = 1 To LastRow
        If AppT.DataBodyRange(i, 5).Value = Firm Then

        'Code here needs to copy the first two cells in the current row of the AppT ListObject

        ' invoiceT.ListRows.Add.Range.PasteSpecial xlPasteValues
        ' Application.CutCopyMode = False


        End If

    Next i


End Sub

1 个答案:

答案 0 :(得分:0)

使用

AppT.DataBodyRange(i,1).Resize(,2).Copy