Select an Option and Invoke the Appropriate Code

Gos-C

Active Member
Joined
Apr 11, 2005
Messages
258
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

I have the following codes:

Code:
Sub oRiskBasedMin()
Dim rskMin As Integer
If Range("EI1") <= 299 Then
        rskMin = 50
ElseIf Range("EI1") <= 499 Then
        rskMin = 75
    ElseIf Range("EI1") <= 699 Then
            rskMin = 100
        ElseIf Range("EI1") <= 4999 Then
                rskMin = 120
            ElseIf Range("EI1") >= 5000 Then
                    rskMin = 175
End If

Range("EJ1") = rskMin

End Sub

Sub iRiskBasedMin()
Dim rskMin As Integer
If Range("EI1") <= 299 Then
        rskMin = 50
ElseIf Range("EI1") <= 499 Then
            rskMin = 100
    ElseIf Range("EI1") <= 699 Then
                rskMin = 125
        ElseIf Range("EI1") <= 999 Then
                    rskMin = 150
            ElseIf Range("EI1") <= 4999 Then
                        rskMin = 175
                ElseIf Range("EI1") >= 5000 Then
                            rskMin = 225
End If

Range("EJ1") = rskMin

End Sub

I want to have the user select either Online or In-Store, and then invoke the appropriate code: If the user selects Online, use the oRiskBasedMin code; if the user selects In-Store, use the iRiskBasedMin code.

Any help, please?

Thank you,
Gos-C
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You could use a MsgBox but that only allows Yes and No, so the wording of the prompt in the box would be a bit laboured.

InputBox relies on the user typing something and then clicking OK, so that would be similarly clunky.

I would probably create a small userform with two buttons captioned Online and In-Store, and have each one call the appropriate subroutine when clicked. At the point where you want the user to decide, simply .Show the form.

Consider having a Cancel button too, if appropriate.
 
Upvote 0
Thank you, Ruddles. I will try the userform listbox.

Regards,
Gos-C
 
Upvote 0
Listbox? It sounds from your description that a pair of command buttons would do the job:-

userform3.jpg
 
Upvote 0
Looks good! Thank you, Ruddles. I will certainly follow your advice.

Cheers,
Gos-C
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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