View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default 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