Variable Not Defined Error!

sameerdoda

New Member
Joined
Dec 22, 2016
Messages
2
Hi All

I am trying to automate the goal seek function and found the following code on one of the sites. The code is supposed to run whenever any changes are made to the sheet. However, I get a "Variable Not Defined" error and C9 is highlighted.

Option Explicit


Private Sub Worksheet_Calculate()
CheckGoalSeek
End Sub


Private Sub CheckGoalSeek()
Range(“C12”).GoalSeek Goal:=0, ChangingCell:=Range(“C9”)
End Sub


I am very new to macros and any help will be really appreciated!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try deleting the quote marks you have around both C12 and C9 and then retype the quote marks using your keyboard and see if that corrects the problem.
 
Upvote 0
Try deleting the quote marks you have around both C12 and C9 and then retype the quote marks using your keyboard and see if that corrects the problem.


Thanks a lot! It worked. And for anyone referring to this thread in the future I used the following code :
Code:
Option Explicit
 
Private Sub Worksheet_Calculate()
CheckGoalSeek
End Sub
 
Private Sub CheckGoalSeek()
Static isWorking As Boolean
 
                If Round(Range("SetCell").Value, 6) <> 0 And Not isWorking Then
isWorking = True
Range("ByChangingCell").Value = 0
Range("SetCell").GoalSeek Goal:=Range("ToValueCell"), ChangingCell:=Range("ByChangingCell")
isWorking = False
End If
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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