PDA

View Full Version : Not able to Add a Scenario



kohli_harshi
08-15-2012, 11:50 AM
I'm getting the following Error while trying to add a Scenario through VBScript Code :-

"Add method of Scenarios class Failed"

Can anyone please give me an idea what I might be doing wrong ?

Kenneth Hobs
08-15-2012, 02:19 PM
Welcome to the forum!

This is a forum for VBA, though vbscript can often use some parts of VBA.

Without code, we can not troubleshoot. When posting code, paste between VBA code tags even though it is vbscript.

I suspect that you have an unhandled error condition. e.g.
Sub t()
On Error Resume Next
With Worksheets("Sheet1")
.Scenarios.CreateSummary resultCells:=.Range("j10,j20")
.Scenarios.Add Name:="Typical", ChangingCells:=.Range("A2,A12"), _
Values:=Array("55", "60")
.Scenarios("typical").Show
End With
End Sub

kohli_harshi
08-15-2012, 09:42 PM
First of all, Thanks Kenneth for the immediate reply :)

This is the code that I'm using :-


'Creating the Excel Application Object
Set objExcel=CreateObject("Excel.Application")
'Creating the Workbook Object
Set objBook=oExcel.Workbooks.Add
'Creating the Worksheet Object
Set objSheet=oExcel.Activesheet

'Adding the Scenario
oSheet.Scenarios.Add "Test","$A$1","1"

kohli_harshi
08-16-2012, 02:36 AM
The Change that I had to make in the code was :-

'Adding the Scenario
oSheet.Scenarios.Add "Test","$A$1",Array("1")