0
votes

I am trying to copy a range of cells from a ListObject in VBA. I don't need the entire row of cells, I just need the cells from the first two columns in the current row of data. I use a "For" statement to go through all of the rows in the table. In the code below, I annotated where I need code.

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
This is not how Stack Overflow works, we don't write code for you - please see How to Ask and minimal reproducible example. - Mathieu Guindon

1 Answers

0
votes

Use

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