Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel question about solver & formulas

Status
Not open for further replies.

marduk813

Programmer
Joined
Jul 18, 2002
Messages
89
Location
US
here's my situation:
i have a vb macro that calls solver to populate its target cell ("Required"). however, if there is data in another cell ("Lump"), then i don't want solver to act, and i want a simple formula to be placed in Required instead.
i've written a simple "if..then" to check for data in Lump, but for some reason it finds data there whether or not there actually is any. here is my code (Required is F7):
Code:
LastYear = 20 + Range("Years").Value
If Range("Lump").Value = "" Then
    SolverOk SetCell:="$E" & LastYear, MaxMinVal:=3, ValueOf:="0", ByChange:="$F$7"
    SolverSolve (True)
Else
    Range("Required").Value = "=C11/C5"
End If
i've also tried the If statement as
Code:
If Range("Lump").Value = 0 Then

but that doesn't work either. neither statements will allow solver to act whether the Lump cell is empty or 0. if Lump contains a number, it works as expected (with the exception that the Required cell is completely black no matter what colors i set for it)

so basically it comes down to this: if the Lump cell is empty or 0, i want solver to act. if it contains a number (other than 0), i want to place a formula in the Required cell and solver will not act.

any ideas?
 
Try

if IsEmpty(Range("Lump").Value) _
or Trim(Range("Lump".Value))="") then
...

IsEmpty is the recommended way but it doesn't work with a space filled cell hence my second condition.

 
thanks plantj. i had forgotten about IsEmpty. i plugged in the code and i'm sure it would work if it weren't for solver still doing something. i can't understand why even when the Lump cell is empty, the Required cell is still filled in with the formula "=C11/C5". i could probably troubleshoot that, but now whatever result shows up in Required (anything not from solver) is black on black, therefore unreadable. no matter what font/background colors i select, if solver doesn't fill in Required, then everything is black.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top