#1   Report Post  
Posted to microsoft.public.excel.misc
Mike
 
Posts: n/a
Default VBA question!?

Hi everyone,

I have this piece of vba code:

Option Explicit
Option Base 1

Dim Budget(1) As Single

Sub Sensitivity()
Dim cell As Range, Mult As Variant, ModelCounter As Integer, _
IncludeConstraint As Boolean
Application.ScreenUpdating = False
SaveOriginalValues
ModelCounter = 0
For Each cell In Range("Multiples")

ModelCounter = ModelCounter + 1
Mult = cell.Value
If IsNumeric(Mult) = True Then IncludeConstraint = True
ChangeModel Mult
RunSolver IncludeConstraint
StoreResults ModelCounter
Next
RestoreOriginalValues
End Sub

Sub SaveOriginalValues()
Dim i As Integer
For i = 1 To 1
Budget(i) = Range("Budget").Cells(i)
Next
End Sub

Sub ChangeModel(Mult As Variant)
Dim i As Integer
If IsNumeric(Mult) = True Then
For i = 1 To 1
Range("Budget").Cells(i) = Mult * Budget(i)
' MsgBox Mult * Budget(i)
Next
End If
End Sub

Sub RunSolver(IncludeConstraint As Boolean)
SolverReset
SolverOk SetCell:=Range("TotProj"), MaxMinVal:=1,
ByChange:=Range("Picked")
SolverAdd CellRef:=Range("Spending"), Relation:=1,
FormulaText:="Budget"

If IncludeConstraint = True Then _
SolverAdd CellRef:=Range("Picked"), Relation:=5
', FormulaText:="Budget"
SolverOptions AssumeLinear:=True, AssumeNonNeg:=True
SolverSolve UserFinish:=True
End Sub

Sub StoreResults(ModelCounter As Integer)
Dim i As Integer
With Range("G2")
For i = 1 To 30
.Offset(i, ModelCounter) = Range("Picked").Cells(i)

Next
' .Offset(i, ModelCounter) = Range("TotProj")
End With
End Sub

Sub RestoreOriginalValues()
Dim i As Integer
For i = 1 To 1
Range("Budget").Cells(i) = Budget(i)
Next
RunSolver True
End Sub


NOW, the results (either 1 or 0) should come out like this:

1 1 0 1
0 1 1 0
1 0 0 1

and so on. Instead I get things like thise:

1
0 1 0 1
1 1 1 0
and so on.

As you see in the first row, I get after the 1st value nothing but
blank. That means somehow my counter is NOT positioned correctly!?

Any help is appreciated....

Thanks,
Mike

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot table question gary Excel Discussion (Misc queries) 1 January 10th 06 06:25 PM
Follow-Up (Clarification) to MIN question Odawg Excel Discussion (Misc queries) 4 October 20th 05 04:04 AM
How do I find and replace a question mark in Excel? Ranpalandil Excel Discussion (Misc queries) 1 September 7th 05 10:20 PM
Hints And Tips For New Posters In The Excel Newsgroups Gary Brown Excel Worksheet Functions 0 April 15th 05 05:47 PM
An easy macro question and one I believe to be a little more diffi TroutKing Excel Worksheet Functions 3 January 18th 05 09:17 PM


All times are GMT +1. The time now is 07:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"