Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default VBA code question?!

Hi everyone,

I have this simple 3 subs vba code. It runs 8 times and each solution
has 24 values that is put in one column of 24 raws. So, the 1st
solution found gets written at N2 to N25....and so on.

The problem I have is this: The 1st solution that gets written from
N2-N25, later it gets removed; just the 1st solution! What could be
causing this in the code? Thanks in advance.

Option Explicit
Option Base 1
Sub Pareto()
Dim cell As Range, ModelCounter As Integer, JobNr As Integer
Dim ret As Integer
Dim ARngSolution As Range

Application.ScreenUpdating = False

ModelCounter = 0
Set ARngSolution = Range("SolDVSens")
ARngSolution.ClearContents

For JobNr = 1 To 8

ret = SolverSolve(UserFinish:=True)

If ret = 0 Or ret = 14 Then
ModelCounter = ModelCounter + 1
RunSolver
StoreResults ModelCounter
End If
Next
End Sub


Sub RunSolver()
SolverReset
SolverOk SetCell:=Range("Obj2"), MaxMinVal:=1,
ByChange:=Range("Picked")
SolverAdd CellRef:=Range("Spending"), Relation:=1,
FormulaText:="Budget"
SolverAdd CellRef:=Range("Picked"), Relation:=5
SolverOptions AssumeLinear:=True, AssumeNonNeg:=True
End Sub

Sub StoreResults(ModelCounter As Integer)
Dim i As Integer
With Range("N1")
For i = 1 To 24
.Offset(i, ModelCounter) = Range("Picked").Cells(i)
Next
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default VBA code question?!

Mike:

The first thing I'd do is set Break Points in the code at various places to
catch what is going on. If you click on the left margin of your code, a red
dot appears (or press F9). This allows you to run the macro with the code
window open using F5, and the code will pause at these points to let you
check the state of variables and the condition of your results. Pressing F5
gain will run the code until the next Break Point.

If I were debugging this, I'd set Break Points at
here If ret = 0 Or ret = 14 Then

ModelCounter = ModelCounter + 1
here RunSolver
here StoreResults ModelCounter

End If

This way, you can check the values of ret and ModelCounter as well as see
what your worksheet looks like after your other Subs run. See if you can
identify at what point the cell goes blank.

Also, you have
Dim cell As Range
Don't use "cell" as it is a valid object name. Use something like "cll" or
"objCell" so you know what it is but Excel doesn't get confused.

Lastly, either post to only one forum, or put both newsgroups in the TO
header. If you put in both NG, any answer will show up on both NG, and
everyone is on the same page. Else you may wind up chasing one thought here
and another there.

HTH
Ed

"Mike" wrote in message
oups.com...
Hi everyone,

I have this simple 3 subs vba code. It runs 8 times and each solution
has 24 values that is put in one column of 24 raws. So, the 1st
solution found gets written at N2 to N25....and so on.

The problem I have is this: The 1st solution that gets written from
N2-N25, later it gets removed; just the 1st solution! What could be
causing this in the code? Thanks in advance.

Option Explicit
Option Base 1
Sub Pareto()
Dim cell As Range, ModelCounter As Integer, JobNr As Integer
Dim ret As Integer
Dim ARngSolution As Range

Application.ScreenUpdating = False

ModelCounter = 0
Set ARngSolution = Range("SolDVSens")
ARngSolution.ClearContents

For JobNr = 1 To 8

ret = SolverSolve(UserFinish:=True)

If ret = 0 Or ret = 14 Then
ModelCounter = ModelCounter + 1
RunSolver
StoreResults ModelCounter
End If
Next
End Sub


Sub RunSolver()
SolverReset
SolverOk SetCell:=Range("Obj2"), MaxMinVal:=1,
ByChange:=Range("Picked")
SolverAdd CellRef:=Range("Spending"), Relation:=1,
FormulaText:="Budget"
SolverAdd CellRef:=Range("Picked"), Relation:=5
SolverOptions AssumeLinear:=True, AssumeNonNeg:=True
End Sub

Sub StoreResults(ModelCounter As Integer)
Dim i As Integer
With Range("N1")
For i = 1 To 24
.Offset(i, ModelCounter) = Range("Picked").Cells(i)
Next
End With
End Sub



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
VBA code question Damian Excel Discussion (Misc queries) 1 September 25th 09 09:54 PM
VBA code question JEV Excel Discussion (Misc queries) 2 March 1st 07 06:02 PM
Code Question Ronbo Excel Programming 3 September 23rd 05 09:33 PM
Code Question Michael168[_111_] Excel Programming 9 September 17th 04 06:31 AM
VBA CODE Question Gary[_5_] Excel Programming 2 July 29th 03 03:45 AM


All times are GMT +1. The time now is 01:43 PM.

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"