Solved

Can't add dynamic range programmatically

Posted on 2013-11-26
4
244 Views
Last Modified: 2013-11-26
I'm trying to add a dynamic range to an Excel workbook. If I use the GUI it works fine, but when I try it programmatically it fails with runtime error 1004.

Name is: Test
Refers to is: =Master!$C$7:INDEX(Master!$C:$C,SUMPRODUCT(--(Master!$C:$C<>""))+5)

Here is the code:
ActiveWorkbook.Names.Add Name:="Test", RefersTo:="=Master!$C$7:INDEX(Master!$C:$C,SUMPRODUCT(--(Master!$C:$C<>""))+5)"

Open in new window

0
Comment
Question by:MacroShadow
  • 2
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39677225
Try

ActiveWorkbook.Names.Add Name:="Test", RefersTo:="=Master!R7C3:INDEX(Master!C3,SUMPRODUCT(--(Master!C3<>""""))+5)"
0
 
LVL 27

Author Closing Comment

by:MacroShadow
ID: 39677312
Thank you, I can't believe I missed the double quotes!
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39677330
You are welcome. I simply put your given formula in through the macro recorder and returned what was recorded.
0
 
LVL 27

Author Comment

by:MacroShadow
ID: 39677340
Nice trick.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Response times in Excel 18 47
learn programming 8 43
how to loop through and process two columns in excel 8 26
batch file or script 4 27
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question