ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using VBA: Avoiding Writing Down Duplicate Solutions (https://www.excelbanter.com/excel-programming/299307-using-vba-avoiding-writing-down-duplicate-solutions.html)

Michael[_27_]

Using VBA: Avoiding Writing Down Duplicate Solutions
 
Hi,

Say I am running a solver 10 times, everytime a solution with 3
components is written into excel table like this

A B C
2.3 3.5 1.4
13.1 4.5 0.5
7.5 6.5 3.2
2.3 3.5 1.4
..
..
and so on. Note that the 1st and 4th solutions are duplicate. I need a
piece of detailed VBA code please that AVOIDS writing-down dupliacte
solutions. So things might look as:

A B C
2.3 3.5 1.4
13.1 4.5 0.5
7.5 6.5 3.2
..
..

Thanks alot,
Mike

Dave Peterson[_3_]

Using VBA: Avoiding Writing Down Duplicate Solutions
 
I don't know how this fits:

dim myRng as range
dim mySolverVal as double
dim destCell as range

mysolverval = 2.3

with worksheets("sheet1")
set myrng = .range("a1",.cells(.rows.count,"A").end(xlup))
if application.countif(myrng,mysolverval) 0 then
'it's a duplicate
else
set destcell = .cells(.rows.count,"A").offset(1,0)
with destcell
.value = application.round(mysolverval,2)
.offset(0,1).value = "next variable"
end with
end if
end with


I added application.round() just to make sure 2.32341231235123 matches
2.32341231235124.

Not sure if you want it.


Michael wrote:

Hi,

Say I am running a solver 10 times, everytime a solution with 3
components is written into excel table like this

A B C
2.3 3.5 1.4
13.1 4.5 0.5
7.5 6.5 3.2
2.3 3.5 1.4
.
.
and so on. Note that the 1st and 4th solutions are duplicate. I need a
piece of detailed VBA code please that AVOIDS writing-down dupliacte
solutions. So things might look as:

A B C
2.3 3.5 1.4
13.1 4.5 0.5
7.5 6.5 3.2
.
.

Thanks alot,
Mike


--

Dave Peterson



All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com