Goal Seek Analysis "If cells are less than 0, than 0" isn't working.

Seric

New Member
Joined
Feb 21, 2019
Messages
10
Office Version
  1. 365
Platform
  1. Windows
WhatIfAnalysis Macro
'
' Keyboard Shortcut: Ctrl+g
'
Public Sub GoalSeeker()


For i = 3 To 187
cells(i, "AG").GoalSeek Goal:=0.15, ChangingCell:=cells(i, "AF")

cells(i, "AF") = WorksheetFunction.Round(cells(i, "AF"), 2)

cells(i, "AF") < 0 = 0


Next i


End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Maybe:

Code:
[COLOR=#333333]WhatIfAnalysis Macro[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]' Keyboard Shortcut: Ctrl+g[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]Public Sub GoalSeeker()[/COLOR]

[COLOR=#333333]For i = 3 To 187[/COLOR]
[COLOR=#333333]    cells(i, "AG").GoalSeek Goal:=0.15, ChangingCell:=cells(i, "AF")[/COLOR]

[COLOR=#333333]    cells(i, "AF") = WorksheetFunction.Round(cells(i, "AF"), 2)[/COLOR]

[COLOR=#333333][FONT='inherit']    If cells(i, "AF") < 0 Then cells(i, "AF") = 0[/FONT][/COLOR]

[COLOR=#333333]Next i[/COLOR]


[COLOR=#333333]End Sub[/COLOR]
 
Upvote 0
you need to say

if cells(i, "AF") < 0 then
cells(i, "AF") = 0
end if
 
Upvote 0

Forum statistics

Threads
1,215,418
Messages
6,124,793
Members
449,189
Latest member
kristinh

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