I am using the following code:
Dim rng As Range
Set rng = Workbooks("import sheet.xls").Sheets("import").Range("project_name,project_author,project_code,project_breaker,default_fault_ac_mcb,default_fault_ac_mccb,default_fault_dc,default_fault_acb,default_rvdrop,default_svdrop,default_eff,default_pfactor,default_ratio,default_freq,default_sfactor_ac,default_spfactor")
For Each cell In rng.Cells
MsgBox cell
Next cell
Now project_name, project_author, etc. are different named ranges in the sheet. The problem is when I add another named range to the above list (already defined), I get a runtime error 1004 (“select method of range class failed”).
Is there a limit to the number of named ranges one can add to range object?
I couldn’t find anything on why this happens but I am still looking.
However this works. You can combine the range using
UNIONUPDATE: I couldn’t find any Microsoft document which describes this behavior, but after some experimentation, I can confirm that the maximum number of named ranges one can add to range object is 16. This behavior can be seen in in Excel 2003, 2007, and 2010.
Strangely this behavior was not replicated in Excel 2011 (MAC). I tested with 19 names and it worked.
MORE UPDATE
After more testing, I discovered that if you name your ranges as
Name1,Name2,Name3etc then I was able to add more named Ranges in Excel 2003-2007-2010. So it has to do something with the naming of the names.I have filed a bug with Microsoft.
SAMPLE FILE FOR TESTING:
https://skydrive.live.com/redir.aspx?cid=cdd3f8abe20bbe3b&resid=CDD3F8ABE20BBE3B!157&parid=CDD3F8ABE20BBE3B!150&authkey=!ADP_QVBopsqenBA