0

I am trying to make simple thing in VBA but I cannot and it drives me crazy. Apologies but I am kinda new to VBA and I want to do it simplest way possible.
I have the following problem:

Sheets("Sheet1").Range("R4").goalseek goal:=1392, ChangingCell:=Sheets("Sheet1").Range("S4")

I wrote this line and it works. Now I would love to make it on passed variables

address.goalseek goal:=value, ChangingCell:=address2
Sub Whatever (address as Range, value as Double, address2 as Range)
    address.goalseek goal:=value, ChangingCell:=address2
End Sub

and to be able to call function/sub from worksheet. Not sure if I should use sub or function. I have every month random(n)-lines that needs to be adjusted so I can not make it static. Tried plenty of things and they do not work.

GSerg
  • 76,472
  • 17
  • 159
  • 346
FilOle
  • 53
  • 1
  • 7
  • Since `.goalseek` modifies cells in the spreadsheet I don't think you can use it inside a user defined function. What you could do is use an even handler such as `Worksheet_Change` so it updates automatically when certain cells change. – John Coleman Apr 08 '20 at 16:12
  • If you record a Macro and click through the steps you need to do, you should have (basically) the code that you want. – ASH Apr 08 '20 at 22:37

0 Answers0