0
Dim LastRow As Long

With Workbooks("SampleBook").Sheets("SampleSheet")
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

I have been running this code for over a month now. I had no issues. Suddenly, for the past two days, it's throwing the subscript out of range - run time error(9).

Not sure what's going on!

Your help is appreciated :)

Thank you!

2
  • 1
    Did you change the name of your workbook or worksheet? Commented Jun 21, 2018 at 18:51
  • Did you rename the workbook or worksheet? Try something like, Dim wb as workbook Dim ws as Worksheet Set wb = Workbooks("SampleBook") Set ws = wb.Sheets("SampleSheet") as see if that runs. Commented Jun 21, 2018 at 18:53

1 Answer 1

1

Figured it out!! I had enabled the show file extension option in folder options. I needed to add the extension to my workbook name. The following modification worked

With Workbooks("SampleBook.xlsm").Sheets("SampleSheet") LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row End With

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

1 Comment

Wasn't there a question several days ago about one computer in a network of many that required the .xlsx extension when naming a workbook in the workbooks collection? Seems this would be the answer.

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.