Souza Saulo
Souza Saulo

Reputation: 61

VBA code to copy the last cells with data in a certain row

I need a code to copy the last 26 cells with data of row 10. I have unsuccessfully tried the following code:

Sub GetLastCells()
    Dim lc As Long
    With ThisWorkbook.Worksheets("PROCV")
         lc = .Cells(10, Columns.Count).End(xlToLeft).Column
         With .Cells(10, lc - 26).Resize(lr, 27).Copy
    End With
    End With
End Sub

Any help would be appreciated.

Upvotes: 0

Views: 320

Answers (1)

Gary's Student
Gary's Student

Reputation: 96781

Easier to see:

Sub GetLastCells()
    Dim lc As Long
    With ThisWorkbook.Worksheets("PROCV")
         lc = .Cells(10, Columns.Count).End(xlToLeft).Column
         kc = lc - 25
         Range(Cells(10, kc), Cells(10, lc)).Copy
    End With
End Sub

Upvotes: 1

Related Questions