How to use goal seek function in Excel user function

0 votes

The following code demonstrates how to utilize goal seek in Microsoft Excel. It runs smoothly.

   Sub GSeek() 
      With Worksheets("Sheet1") 
             .Range("H18").GoalSeek _  
              Goal:=.Range("H21").Value, _ 
               ChangingCell:=.Range("G18")
     End With 
   End Sub

And I would like to use a function to do the goal seek like follows.

  Function fSeek(a As Range, b As Range, c As Range)
     a.GoalSeek Goal:=b.Value, ChangingCell:=c
     fSeek = "Ok"
   End Function

The code, however, operated without incident, and the range c received no response. Where have I gone wrong?

Oct 28, 2022 in Others by Kithuzzz
• 38,000 points
776 views

1 answer to this question.

0 votes

In the Microsoft Excel Object-Sheet1(Sheet1), we can only write the following code:

 '----------------------------------------------
 ' Goal seeking when the worksheet changes.
 '----------------------------------------------
 ' Here we want to do goal seek for Range("H18") 
 '  with the Goal cell as  Range("H21") 
 '  and  the changing cell as Range("G18").
 '
 Private Sub Worksheet_Change(ByVal Target As Range)
     Range("H18").GoalSeek Goal:=Range("H21"), ChangingCell:=Range("G18")
 End Sub
answered Oct 28, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How do I use the Indirect Function in Excel VBA to incorporate the equations in a VBA Macro Function

Try this: Sub Test() Dim str As String: str ...READ MORE

answered Jan 19, 2023 in Others by narikkadan
• 63,600 points
1,037 views
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
3,721 views
+1 vote
1 answer

How to use VBA in Excel for Google Search?

Try this: Private Const LicenseRegistration As String = ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 63,600 points
1,706 views
0 votes
1 answer

Excel Function Goal Seek Equivalent Algorithm in C #

Nuget has libraries available like Trident.GoalSeek and ...READ MORE

answered Oct 17, 2022 in Others by narikkadan
• 63,600 points
1,664 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,212 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,664 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
908 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,053 views
0 votes
1 answer

How to use the INDIRECT function in Excel

Try this: =INDEX(INDIRECT($A$1&"!$1:$1048576"),MATCH($B$1,INDI ...READ MORE

answered Sep 29, 2022 in Others by narikkadan
• 63,600 points
891 views
0 votes
1 answer

How to use VLOOKUP function in MS Excel

Here is the formula for cell G2: ...READ MORE

answered Nov 13, 2022 in Others by narikkadan
• 63,600 points
525 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP