VBA: Error 1004: Select Method of Range class failed

--ndn.diva--

New Member
Joined
Jun 23, 2008
Messages
12
I'm writing a macro to retrieve data from an Excel add-in. It's only a few lines of code, and I've written it several times and it has worked perfectly. However, this time, I get an error message: Select Method of Range class failed.
The section of code that is causing the problem is:
If (Range("Month") = "9") Then
Sheets("Analysis May 08 NLD").Activate
Range("A2:B51").Select 'code that is causing the problem
Application.Run ("EssmenuRetrieve")
Sheets("Analysis May 08 LDD").Activate
Range("A2:B51").Select
Application.Run ("EssmenuRetrieve")
MsgBox ("Data Retrieved")

The value in the cell "Month" is 9, so that part of the code is working properly. I've tried changing the value in that cell to another number, and running the code, after changing the sheet name to the corresponding month, however, I got an error at the same point.
I've made sure that everything is typed in correctly (as i said, i've written this bit of code before).

Any suggestions?
Thanks!!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You might have typed everything in correctly, but are you sure you are referencing everything correctly?

Without a worksheet reference here VBA will be looking at the range on what it regards as the active sheet.
Rich (BB code):
Range("A2:B51").Select
 
Upvote 0
What do you mean by "worksheet reference"?
The macro is reaching the correct worksheet. (I checked this by having excel display a message box after each line of code)
 
Upvote 0
What I mean is exactly what I said.:)
Without a worksheet reference here VBA will be looking at the range on what it regards as the active sheet.
This will explicitly reference the range on the Analysis... sheet.
Rich (BB code):
Sheets("Analysis May 08 NLD").Range("A2:B51").Select 

Though I'm not sure what you are actually trying to do and/or whether the problem is with the code you've posted.

It's not normally needed to use select and you are calling other subs, where the problem might actually be.:)
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top