Solved

Can't add dynamic range programmatically

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

912 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now