1

The object Error keeps appearing no matter what I try. I'm not that experienced in VBA.

Its appears to be when I'm giving the "lastrow" variable a value.

Const sFILE_PATH    As String = "C:\Users\Downloads\"
Const sEXTENSION    As String = ".xlsm"

Dim lastrow As Long
Dim lastrow_Offset As Long: lastrow_Offset = ThisWorkbook.Sheets("Test").Cells(Rows.Count, "h").End(xlUp).Row

Dim wbk As Workbook
Dim sFileName As String

sFileName = "2018-12"
Set wbk = Workbooks.Open(sFILE_PATH & sFileName & sEXTENSION)

Set lastrow = wbk.Sheets("Acc").Cells(Rows.Count, "C").End(xlUp).Row
2
  • 6
    Remove the Set command before populating the variable. The command .row returns a number, not a range. Commented Jan 8, 2019 at 10:21
  • 1
    I would break the last statement into different statements and see which one fails Commented Jan 8, 2019 at 10:21

1 Answer 1

1

You've defined Dim lastrow As Long so it's not an object which needs to be Set. It's a variable that needs to be assigned

lastrow = wbk.Sheets("Acc").Cells(Rows.Count, "C").End(xlUp).Row

I haven't tested this against your implied workbook structure but assume wbk.Sheets("Acc").Cells(Rows.Count, "C").End(xlUp).Row evaluates to a Long

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.