strattergize
New Member
- Joined
- Nov 24, 2007
- Messages
- 12
I have written a simple macro to allow me to GoalSeek over a range instead of a single cell (requiring that the values all be goalseeked to zero variance).
It's been a long time since I have worked with forms, however, and there is a lot I don't recall.
At this point, I have the main macro written and have attached it to a simple userform that I created (named: GoalSeekAcrossRanges). The form has 2 RefEdit ranges to gather ranges from the user, an OK command button, and CANCEL command button.
***My question is how I can launch/show the userform when I want to access the form? *** Ideally, I would want to launch it from a custom menu that I have built that launches based on pushing Ctrl+m (accesses an .xlam file that I saved as an add-in). Any help would be appreciated. Thanks.
Jared
I have included a bit of my sample code below. It is within the code of the Form:
--------------------------------------------------------------
Private Sub UserForm_Initialize()
Me.Show
End Sub
Private Sub cmdCancel_Click()
Me.Tag = "Canceled"
Me.Hide
End Sub
Private Sub cmdOK_Click()
GoalSeek
Me.Hide
End Sub
Sub GoalSeek()
Set rRange1 = Range(Me.RefEdit1.Text)
Set rRange2 = Range(Me.RefEdit2.Text)
For Each c In rRange1.Cells
i = i + 1
Set SetToCell = rRange1.Cells(i)
Set ByChangingCell = rRange2.Cells(i)
SetToCell.GoalSeek Goal:=0, ChangingCell:=ByChangingCell
Next
rRange1.Cells(1).Select
End Sub
It's been a long time since I have worked with forms, however, and there is a lot I don't recall.
At this point, I have the main macro written and have attached it to a simple userform that I created (named: GoalSeekAcrossRanges). The form has 2 RefEdit ranges to gather ranges from the user, an OK command button, and CANCEL command button.
***My question is how I can launch/show the userform when I want to access the form? *** Ideally, I would want to launch it from a custom menu that I have built that launches based on pushing Ctrl+m (accesses an .xlam file that I saved as an add-in). Any help would be appreciated. Thanks.
Jared
I have included a bit of my sample code below. It is within the code of the Form:
--------------------------------------------------------------
Private Sub UserForm_Initialize()
Me.Show
End Sub
Private Sub cmdCancel_Click()
Me.Tag = "Canceled"
Me.Hide
End Sub
Private Sub cmdOK_Click()
GoalSeek
Me.Hide
End Sub
Sub GoalSeek()
Set rRange1 = Range(Me.RefEdit1.Text)
Set rRange2 = Range(Me.RefEdit2.Text)
For Each c In rRange1.Cells
i = i + 1
Set SetToCell = rRange1.Cells(i)
Set ByChangingCell = rRange2.Cells(i)
SetToCell.GoalSeek Goal:=0, ChangingCell:=ByChangingCell
Next
rRange1.Cells(1).Select
End Sub