View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
abcd[_2_] abcd[_2_] is offline
external usenet poster
 
Posts: 52
Default Create scenarios using macro and data in cells

Sub CreateScenario()
Dim line&, thename$, thevalues
Const thecells$ = "R1C1:R1C2" 'this mean "A1:B1" in RC syntax
' R1C1 means Row 1 and Column 1

For line = 2 To 4 'data rows to be added
thename = "scenario" & line
thevalues = Array(CStr(Cells(line, 1).Value), _
CStr(Cells(line, 2).Value))
' cells( row number , column number)

ActiveSheet.Scenarios.Add name:=thename, _
ChangingCells:=thecells, _
values:=thevalues, _
Comment:="macro created", _
Locked:=False, Hidden:=False

Next line
End Sub