Excel VBA Userform command button link to goalseek module

leyan

New Member
Joined
Nov 18, 2013
Messages
13
Office Version
  1. 365
Platform
  1. Windows
I need to calculate goalseek for a range of data, and i have created a module to run the calculation. I also created a userform so I can input the variables.
what code should I put for command button so when I click the PO calculation button, it will run the goal seek function with those 3 variables? Thanks

Sub CheckGoalSeek()
Load UserForm1
UserForm1.Show
Dim i&, r As Range
On Error Resume Next
For i = 3 To 30
Set r = Range(UserForm1.TargetMOH.Text & i)
If r.Value = 0 Then
Resume Next
Else
r.goalseek Goal:=UserForm1.MOH.Value, _
ChangingCell:=Range(UserForm1.Adjustment.Text & i)
IF_FUNCTION
End If
Next
On Error GoTo 0
End Sub
 

Attachments

  • Userform1.png
    Userform1.png
    9.1 KB · Views: 5
  • Userform code.png
    Userform code.png
    16 KB · Views: 5

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
i have fixed the issue and it is caused by Tab order.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,388
Members
448,957
Latest member
Hat4Life

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