Ahhh, your sample should go like this:
You should find that runs without error. I think maybe you are not understanding the hierarchical object model of Excel. The object model starts of with an Application object, which can have one or many workbooks. Each Workbook can have one or many sheets. A range belongs to a particular sheet, it is not independent of a sheet. So you can't have a range defined in code (your "ran" variable) that you can use across workbooks. Each time you change the workbook, you must change the definition of the "ran" with a Set statement. Maybe you understand this, maybe you don't, I aren't being patronising, it just looks like maybe you don't understand from your code.
In this way, when you define a Workbook, it will pay to define the worksheet as well as your range. And to do so, use the higher level object. An example is below:
Now you should be able to see the cascading hierarchy clearly. The Application you don't need to define as it defaults to your current application. The Workbook is next level down, define it first. Use the Workbook to define the Worksheet. Then use the Worksheet to define the range. If you always do it this way it becomes a lot less confusing!
Bookmarks