I'm trying to get the last row of data after opening an excel Workbook but it's returning "Run Time Error 1004: Application-defined or object-defined error" I've used this format for code many times so I'm not sure what I'm missing here. I defined the variable as Long, does anyone have any ideas? My code is below:
Function get_end_row(ByVal column_with_data As Long) As Long
Dim last_row As Long
last_row = ThisWorkbook.Sheets(1).Rows.Count
get_end_row = ThisWorkbook.Sheets(1).Cells(last_row, column_with_data).End(xlUp).Row
End Function
Sub Master()
Call MVP
End Sub
Sub MVP()
Dim endRow As Long
Dim wb As Workbook, ws As Worksheet
Dim lastRow1 As Long
Set wb = ThisWorkbook
Set ws = ThisWorkbook.Sheets(1)
endRow = get_end_row(1)
Set mvpcomm = Workbooks.Open("File Path")
Set wsMVPComm = mvpcomm.Sheets("Combined")
lastRow1 = wsMVPComm.Range("A" & Rows.Count).End(xlUp).Row
wsMVPComm.Range("A2:AZ" & lastRow1).Copy Destination:=ws.Range("A" & endRow + 1)
End Sub
If anyone has any ideas I'd really appreciate it! Thank you.
wsMVPComm.Range("A" & wsMVPComm.Rows.Count).End(xlUp).RowlastRow1 = wsMVPComm.Range("A" & wsMVPComm.Rows.Count).End(xlUp).Row