View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tushar Mehta[_6_] Tushar Mehta[_6_] is offline
external usenet poster
 
Posts: 19
Default Setting a Solver constraint using vba?

[This followup was posted to microsoft.public.excel.programming with an
email copy to Tony Scullion.
Please use the newsgroup for further discussion.]

To get the code to add a Solver constraint, turn on the macro recorder
(Tools | Macro Record new macro...), and add the constraint through
the GUI.

Then, add a loop and an IF statement along the lines of the untested:

Dim i as Long
....
for i=11 to 15
IF isempty(range("U" & i)) then
else
{add constraint here, adjusting the generated code to apply to
Range("U" & i)}
end if
next i

--
Trouble finding replies to your posts? Use a newsreader. See the
tutorial 'Outlook Express and Newsgroups' on my web site

Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions


In article ,
says...
Hi Group,

How do I add constraints in Solver whereby it checks cells
U11:U15 for data and, if data exists, then make it match
the constraints that I'm trying to apply. If no data
exist then ignore the constraints altogether.

Currently, I have Solver set-up to check if an entry
exists using <=. This works fine if data exists but if
there is no data it tries to match a blank entry.

I think this needs to be done using vba - does someone
know how to help me.

Thanks

Tony