Help with Sub

LRoy

New Member
Joined
Aug 5, 2022
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
I'm still quite new to VBA.

I have created this Subroutine which is called upon in another Sub.
The idea of it, is to search for the cell which contains "<Config Version=" and then select the cell next to it.
This cell is then updated with the latest version number.

Now this sub works perfectly fine as long as I have the "Hidden" worksheet open when I run it. If I attempt to run it whilst any other worksheet is open then it gives me the error:

Run-time error '1004':
Select method of Range class failed

I know I could probably solve this by just selecting the worksheet first, but I feel like that doesn't really address the problem.

The line highlighted is where I get the error, I've been told it's best to avoid using 'Select' and I believe this may be what's causing my error, but I'm not sure how else to go about selecting that specific cell.

Any help appreciated.

Thanks in advance.
 

Attachments

  • 20220822_094238_708.png
    20220822_094238_708.png
    18.6 KB · Views: 12

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You can't select a cell unless its sheet is active. You don't need it there - just write the value to the cell by replacing .Select with .Value = "whatever"
 
Upvote 0
Solution
You can't select a cell unless its sheet is active. You don't need it there - just write the value to the cell by replacing .Select with .Value = "whatever"
This has done it, thank you!
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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