0

I am trying to use the consolidate functionality to sum a number of sheets (with the names apples and oranges), with the same template into one master template.

ConsolidateRange is the tab names and the ranges to use in the consolidation.

Master is the name of the sheet that I am trying to output the sum to.

Here is my code:

ConsolidateRange = "apples!R1C1:R37C6, oranges!R1C1:R37C6"
    
    Worksheets("Master").Range("A1").Consolidate _
    Sources:=Array(ConsolidateRange), _
    Function:=xlSum

The error that I'm getting is 'Cannot open consolidation source file 'apples'.

1 Answer 1

2

you have to declare a Variant and fill it with Array() function

Dim ConsolidateRangeArray As Variant

ConsolidateRangeArray = Array("apples!R1C1:R37C6", "oranges!R1C1:R37C6")

Worksheets("Master").Range("A1").Consolidate _
Sources:=ConsolidateRangeArray, _
Function:=xlSum

or use Split() to make a String array out of a string with substrings separated by a delimiter

Dim ConsolidateRange As String

ConsolidateRange = "apples!R1C1:R37C6,oranges!R1C1:R37C6"

Worksheets("Master").Range("A1").Consolidate _
Sources:=Split(ConsolidateRange, ","), _
Function:=xlSum
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, but when I try I still getting the Cannot open consolidation source file 'apples' error
are those worksheets both in the same, active, workbook?
Hi, apples and oranges are tabs in the active workbook
both my codes (as you see them in their last edit) work with sheets named after "Master", "apples" and "oranges". So double check your code for every single statement remembering that all commas and spaces must be where you see them and must not be where you don't see them
Thanks my bad the file name was ' apples' (with a space at the front and not 'apples', works great thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.