Forum Discussion
hrh_dash
Sep 06, 2022Iron Contributor
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...
- 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
Harun24HR
Sep 06, 2022Bronze Contributor
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
hrh_dash
Sep 07, 2022Iron Contributor
the code works perfectly. thank you for the assistance!