• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro with Named Ranges

Suneil

New Member
I am looking for a way to work with named ranges in Excel Macros, when the same macro is to be run on multiple named ranges.

I have written a Macro (Macro1) in a particular sheet (Sheet 1) which have named references (E.g. Aa1). Now I have to copy this sheet multiple times (Sheet 2, Sheet 3, etc). The named reference would get copied along with during the copying process (Aa1 in Sheet 2, Aa1 in Sheet 3).

When operations are done, it seems to reference only the first occurrence of the named range, i.e. Aa1 in Sheet 1 and not in Sheet 2 or Sheet 3. The same should be applicable while running the macro also.

To get over this and correctly reference the cells in each sheet, I can rename the named range accordingly - rename to Aa2 in Sheet 2, to Aa3 in Sheet 3, etc.

However, only the named range Aa1 would be referred in Macro1. How do I make the Macro run using some loop for all the named ranged? E.g. if i=2, the named range referred would be Aa2, if i=3, the named range referred would be Aa3, etc.

That is how does one replicate the same Macro across Sheet 2, Sheet 3, etc without copying it multiple times?
 
Hi Suneil

Welcome to Chandoo forum :)

You can 't use AA1 as a named Range. This is a cell reference? XL will not allow it. What are you trying to do exactly? As the named Range is in the same place each time you could trap its whereabouts (in case it moves) with vba and perform your action.

Take care

Smallman
 
Back
Top