Conditional Goal Seek VBA

gsemaan

New Member
Joined
Jul 25, 2014
Messages
3
Hi,

I am trying to write a script for a conditional goal seek. If the value sought in cell B1 is less than 0, I would like the message box to return language that says, "Growth from A may not exceed growth from B". If the value in B1 is greater than 0, I would like the message box to return language that says, "Optimal Growth - XX.XX%"

My issue with the below is that I have to run the macro twice in order to get my first language that growth A may not exceed growth B. I only want to have to run the macro once.

Any help is much appreciated.

Sub Optgrwth()
Dim SPGrowth As Integer, result As String
SPGrowth = Range("B1").Value


Range("C1").GoalSeek Goal:=0, ChangingCell:=Range("B1")
For Each EQ In ActiveSheet.Range("C1")


If SPGrowth < 0 Then
MsgBox "Growth from A may not exceed growth from B"


ElseIf EQ.Value = 0 Then
MsgBox "Optimal Stock Growth - " & (Format(Range("B1"), "#.####%"))
Else


End If
Next EQ


End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,214,606
Messages
6,120,484
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top