Forum Discussion

hrh_dash's avatar
hrh_dash
Iron Contributor
Sep 06, 2022
Solved

Get value from lastrow and lastcol VBA

How do i amend the code below to get value from a lastrow and lastcol any data. When the code executed, it should be populating value of $1,350   Dim lastRow_TCA_corp as long Dim lastCol_TCA as l...
  • Harun24HR's avatar
    Sep 06, 2022

    hrh_dash Last line of your code is problematic. Try below codes.

    Sub LrLc()
        Dim lastRow_TCA_corp As Long
        Dim lastCol_TCA As Long
        Dim Destws_TCA_corp As Worksheet
        Dim Destwb_TCA_corp As Workbook
        Set Destwb_TCA_corp = Workbooks.Open(filename_TCA_corp)
        Set Destws_TCA_corp = Destwb_CMS_corp.Sheets("Collection for Invoicing")
        
        lastRow_TCA_corp = Destws_TCA_corp.Cells(Destws_TCA_corp.Rows.Count, "A").End(xlUp).Row
        
        lastCol_TCA = Destws_TCA_corp.Cells(1, Columns.Count).End(xlToLeft).Column
        
        ws.Range("B28").Value = Destws_TCA_corp.Cells(lastRow_TCA_corp, lastCol_TCA).Value
    End Sub

Resources