Hello,
At work we have a large worksheet of housing data that gets automatically updated every morning. I would like to create a working copy that is less cumbersome to navigate and which is automatically updated with information from the latest version of the original spreadsheet every time you open it.
The idea is on opening the copy you clear the contents and copy into it those of the original worksheet. Here's the code I've created so far (with the file names edited for security reasons):
The error in the thread title occurs whenever I try to open the worksheet that the updated information is supposed to go into (line 7) - I looked at a thread on Stack Overflow posted by a user with the same problem (Out of range error for Windows().Activate), and a variety of solutions were offered and I was unsure which one to use.
Can anyone explain why this error is occurring and how to rectify the code so that it does what I want it to do? The error originally occurred when I just used the file name in the Activate command, but as you can see it does not work even when I include the full path.
At work we have a large worksheet of housing data that gets automatically updated every morning. I would like to create a working copy that is less cumbersome to navigate and which is automatically updated with information from the latest version of the original spreadsheet every time you open it.
The idea is on opening the copy you clear the contents and copy into it those of the original worksheet. Here's the code I've created so far (with the file names edited for security reasons):
VBA Code:
Sub UpdateWorksheet()
Range(Cells(2, 1), Cells(Application.WorksheetFunction.CountA(Range("a:a")), 25)).Select
Selection.ClearContents
Workbooks.Open "S:\R\A\T\T.xlsx"
Range(Cells(2, 1), Cells(Application.WorksheetFunction.CountA(Range("a:a")), 25)).Select
Selection.Copy
Windows("S:\R\A\T\T - Copy.xlsx").Activate
ActiveSheet.Paste
Columns("A:Y").EntireColumn.AutoFit
Range("A2").Select
The error in the thread title occurs whenever I try to open the worksheet that the updated information is supposed to go into (line 7) - I looked at a thread on Stack Overflow posted by a user with the same problem (Out of range error for Windows().Activate), and a variety of solutions were offered and I was unsure which one to use.
Can anyone explain why this error is occurring and how to rectify the code so that it does what I want it to do? The error originally occurred when I just used the file name in the Activate command, but as you can see it does not work even when I include the full path.