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.
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!
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!