Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2009, 02:58 PM
Registered User
 
Join Date: Dec 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default string variable for consolidation

Would you be able to help me run a consolidation using a string variable for the "sources" argument? The consolidation runs fine using both specific ranges or named ranges as shown in versions 1 and 2 below. As soon as I substitute a variable for the sources as in version 3, I receive an error message that it cannot open the source file. This is true even with the variable set to the exact same string as in either 1 or 2. I've also tested it running the consolidation from another workbook.
Thanks very much for your guidance.


1 and 2 below both run correctly:

Code:
(1) ThisWorkbook.Sheets(1).Range("B19").Consolidate Sources:=Array("Sheet1!R2C2:R8C6", "Sheet1!R10C2:R16C6"), Function:=xlSum

(2) ThisWorkbook.Sheets(1).Range("B19").Consolidate Sources:=Array("'C:\testconsolidate.xls'!group1", "'C:\testconsolidate.xls'!group2"), Function:=xlSum
but the consolidation doesn't run with a variable for sources, for example:

Code:
strNmrng = "'C:\testconsolidate.xls'!group1" & ", " & "'C:\testconsolidate.xls'!group2"

(3) ThisWorkbook.Sheets(1).Range("B19").Consolidate Sources:=strNmrng, Function:=xlSum
#3 returns error that cannot open source file testconsolidate.xls





Similar Threads
Thread Thread Starter Forum Replies Last Post
consolidation of xls problem Nehru C# 1 July 24th, 2013 05:22 AM
Calling c# String variable help simonlm C# 2005 0 May 25th, 2007 04:01 AM
Excel Consolidation ! sriramus Access VBA 1 February 28th, 2006 08:33 AM
C# String to Variable? MAtkins General .NET 4 October 2nd, 2005 04:47 PM
consolidation thelos Excel VBA 0 September 5th, 2005 05:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.