Hello...
I've got a question to 2almost similar VBA-code lines, difference a) is with "With / End With", b) is without :"With / End With" ....
a)
sourceDataValue = "Data!R1C1:R" & ResultRows + 1 & "C" & ResultCols
With ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase)
.SourceData = sourceDataValue
.CreatePivotTable TableDestination:="R" & CreatePivotAt & "C1", _
TableName:=PivotName, _
DefaultVersion:=xlPivotTableVersion10
End With
b)
sourceDataValue = "Data!R1C1:R" & ResultRows + 1 & "C" & ResultCols
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
sourceDataValue).CreatePivotTable TableDestination:="R" & CreatePivotAt & "C1", _
TableName:=PivotName, DefaultVersion:=xlPivotTableVersion10
In my VBA Code, a) is not working, b) is working perfectly.
What is the reason for one is working and the other not?
Bookmarks