(Solved) – Excel VBA: Can not open Consolidate sources file

  • by
(solved)-–-excel-vba:-can-not-open-consolidate-sources-file

I trying to use Consolidate in Excel VBA to sum the Data from one sheet (Sheet1) to Sheet “Total”.
When i do it

Sub Sumdata()
Sheets("Total").Select
Range("A1").Select
Selection.Consolidate sources:="Sheet1!R1C1:R12C2" _
, Function:=xlSum, TopRow:=True, LeftColumn:=True, CreateLinks:=False
End Sub

=> It’s OK.
But now i want to replace Sheet1 by String variable, like this

Sub Sumdata()
Dim a As Variant
a = "Sheet1"
Sheets("Total").Select
Range("A1").Select
Selection.Consolidate sources:="a!R1C1:R12C2" _
, Function:=xlSum, TopRow:=True, LeftColumn:=True, CreateLinks:=False
End Sub

It’s not working and have a notification “Can not open Consolidate sources file ‘a’ “.
How can i fix it.
Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *