Solved

Can't add dynamic range programmatically

Posted on 2013-11-26
4
235 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple Open Excel Spreadsheets 12 40
Excel calculate based on 'x' in column 2 25
Excel VBA 4 26
Select/Copy row and pasting it lower in sheet 7 19
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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