Randomly Selects Items Based Off Multiple Criteria

eldakim

New Member
Joined
Aug 1, 2016
Messages
1
Hello, everyone. I am currently creating a random generator that randomly selects restaurants based off selected criteria. So say I want to eat Japanese food within a certain price range. The worksheet should filter through a large table of cuisines and randomly produce an output that contains my selection.

My first table in the worksheet allows you to select the preferred cuisine through a combo box and select the price range (indicated as "$" signs) through another combo box. This part, I created the appropriate macros, so it isn't an issue.

The second table produces the output after the user clicks the command button (indicated as "randomize"). The outputs are: restaurant, review rating, and price. These were all populated on a second worksheet. In order to get the result for restaurants, I used this code for the command button.

Code:
Private Sub CommandButton1_Click()

CommandButton1.Caption = "Randomize"
Dim cuisine As String, result As String

cuisine = Range("A11").Value

If cuisine = ("Korean")" Then
result = Worksheets(Food List").Range("D9").Value

Elseif cuisine = ("Chinese") Then
result = Worksheets("Food List").Range("D2").Value

Elseif cuisine = ("Western") Then
result = Worksheets ("Food List").Range("D19").Value

End If

Range("A17").Value = result

End Sub

This script was created before I considered adding in the price, so it is rather simplified. The result value comes from the second sheet, where the indicated cell was produced via "random" function I created: =INDEX(A2:A5, RANDBETWEEN(1, COUNTA(A2:A5)),1)

So basically, the result looks into the excel formula I created on the second sheet. I don't know any "random generation" macro, so I used the excel function as substitute.


Is there a way for me to consider both the cuisine and price to produce a random result? I apologize if what I wrote is a tad bit incoherent, and I will clarify the best way I can if needed.

Many thanks!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,215,817
Messages
6,127,041
Members
449,356
Latest member
tstapleton67

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