Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Using VBA: Trying to write new solutions ONLY

Hi,

I have this piece of VBA code. I want to write new solutions only as I
am running the solver 50 times for example. See explanations in the
code with questions (each solution is an array of values not single
value):

Dim rng As Range
Dim cella As Range
Dim cell1 As Range
Dim i As Long
Dim cnt As Long
Dim bDup As Boolean

If Not IsEmpty(Cells(10, 3)) Then
' 1st value of 1st solution array is in cell (10,3)

Set rng = Range(Cells(10, 3), Cells(59, 3).End(xlUp))
' 1st solution array starts in cell(10,3), and the 50th solution array
starts
' at cell(59,3)

For Each cella In rng
i = 0
cnt = 0
bDup = False

For Each cell1 In cella.Resize(10, 10)
'each solution array has 10 values

For Each mac In vehicleModel.Macros
solutionArray(i) = mac.Value
' How do you define solutionArray as an array?

If cell1.Value = solutionArray(i) Then
cnt = cnt + 1
End If
Next mac
i = i + 1
Next
If cnt = 10 Then
bDup = True
Exit For
End If
Next
End If
If Not bDup Then
' write array

Help to make this VBA code work would be greatly appreciated.

Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using VBA: Trying to write new solutions ONLY

Dim rng As Range
Dim cella As Range
Dim cell1 As Range
Dim i As Long, k as Long
Dim cnt As Long
Dim bDup As Boolean
Dim SolutionArray(0 to 9) as Variant

for k = 1 to 50
' run the model

' now gather the results
For Each mac In vehicleModel.Macros
solutionArray(i) = mac.Value
Next


If Not IsEmpty(Cells(10, 3)) Then
' 1st value of 1st solution array is in cell (10,3)

Set rng = Range(Cells(10, 3), Cells(60, 3).End(xlUp))
' 1st solution array starts in cell(10,3), and
' the 50th solution array starts
' at cell(59,3)

For Each cella In rng
i = 0
cnt = 0
bDup = False


For Each cell1 In cella.Resize(10, 10)
If cell1.Value = solutionArray(i) Then
cnt = cnt + 1
End I
i = i + 1
Next
If cnt = 10 Then
bDup = True
Exit For
End If
Next
End If
If Not bDup Then
' write array

Next k ' next model run

also see an example in the original thread.

--
Regards,
Tom Ogilvy


"Michael" wrote in message
om...
Hi,

I have this piece of VBA code. I want to write new solutions only as I
am running the solver 50 times for example. See explanations in the
code with questions (each solution is an array of values not single
value):

Dim rng As Range
Dim cella As Range
Dim cell1 As Range
Dim i As Long
Dim cnt As Long
Dim bDup As Boolean

If Not IsEmpty(Cells(10, 3)) Then
' 1st value of 1st solution array is in cell (10,3)

Set rng = Range(Cells(10, 3), Cells(59, 3).End(xlUp))
' 1st solution array starts in cell(10,3), and the 50th solution array
starts
' at cell(59,3)

For Each cella In rng
i = 0
cnt = 0
bDup = False

For Each cell1 In cella.Resize(10, 10)
'each solution array has 10 values

For Each mac In vehicleModel.Macros
solutionArray(i) = mac.Value
' How do you define solutionArray as an array?

If cell1.Value = solutionArray(i) Then
cnt = cnt + 1
End If
Next mac
i = i + 1
Next
If cnt = 10 Then
bDup = True
Exit For
End If
Next
End If
If Not bDup Then
' write array

Help to make this VBA code work would be greatly appreciated.

Mike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Using VBA: Trying to write new solutions ONLY


Tom,

It is giving me no errors but still not working as if it is not there!

I do understand your example well. I tried it separately and did work
fine. However, there is one difference he you assume that the 1000
solutions are already there!

In my case, at each new run it has to check with the previous unique
ones for comparison (i.e. written ones).

So, if I am running the model 50 times, the comparisons are done 50
times too (may be 49 times since the 1st is always unique).

Each solutionArray(0 To 7) has 8 components, the model runs 50 times,
1st solutionArray is from cell(10,3) to cell(10,10).

With that in mind, is your last piece of code still valid or needs some
change?

Thanks for your patience indeed.

Mike


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using VBA: Trying to write new solutions ONLY

If you are going to run the macro after each run of the model, then the only
change would be to take out the loop that ran the model. There was a typo
on the resize command - it was resize(10,10) and should have been
resize(1,10), now resize(1,8) if you only have 8 values in the solution
array. My example doesn't assume the 1000 arrays are all there. It checks
them one at a time as they are generated. They are just all generated in a
loop in the macro. The same yours would be it you could automate the
running of your model.

Dim rng As Range
Dim cella As Range
Dim cell1 As Range
Dim i As Long, k as Long
Dim cnt As Long
Dim bDup As Boolean
Dim SolutionArray(0 to 7) as Variant

' the model has just been run so
' now gather the results
i = 0
' I have no idea what vehicleModel.Macros is, but assume
' it will fill your array with the necessary values.
For Each mac In vehicleModel.Macros
solutionArray(i) = mac.Value
i = i + 1
Next


If Not IsEmpty(Cells(10, 3)) Then
' 1st value of 1st solution array is in cell (10,3)

Set rng = Range(Cells(10, 3), Cells(60, 3).End(xlUp))
' 1st solution array starts in cell(10,3), and
' the 50th solution array starts
' at cell(59,3)

For Each cella In rng
i = 0
cnt = 0
bDup = False


For Each cell1 In cella.Resize(1, 8)
If cell1.Value = solutionArray(i) Then
cnt = cnt + 1
End I
i = i + 1
Next
If cnt = 8 Then
bDup = True
Exit For
End If
Next
End If
If Not bDup Then
' write array


--
Regards,
Tom Ogilvy



"Michael Sultan" wrote in message
...

Tom,

It is giving me no errors but still not working as if it is not there!

I do understand your example well. I tried it separately and did work
fine. However, there is one difference he you assume that the 1000
solutions are already there!

In my case, at each new run it has to check with the previous unique
ones for comparison (i.e. written ones).

So, if I am running the model 50 times, the comparisons are done 50
times too (may be 49 times since the 1st is always unique).

Each solutionArray(0 To 7) has 8 components, the model runs 50 times,
1st solutionArray is from cell(10,3) to cell(10,10).

With that in mind, is your last piece of code still valid or needs some
change?

Thanks for your patience indeed.

Mike


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Using VBA: Trying to write new solutions ONLY





*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using VBA: Trying to write new solutions ONLY

Little light on content Michael.

--
Regards,
Tom Ogilvy

"Michael Sultan" wrote in message
...




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
IF formula with many solutions. Jaime.CIS New Users to Excel 5 December 7th 06 08:25 PM
lookup & match solutions ieatboogers Excel Worksheet Functions 0 November 16th 05 11:32 PM
VBA to write Unique Solutions ONLY? Michael[_27_] Excel Programming 3 May 22nd 04 05:41 PM
Using VBA, how to write unique solutions only? Michael[_27_] Excel Programming 0 May 6th 04 04:27 PM
Looking for Solutions Tony Johnson Excel Programming 6 August 14th 03 03:03 PM


All times are GMT +1. The time now is 09:30 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"