Grouping Values for a Macro?

Forever_EX

New Member
Joined
Mar 26, 2018
Messages
22
I'm beginning to learn to code in Excel, and I have a question about grouping items.

I have about 100 different "types" of items that are separated into about 5 groups based on how I describe the item.

I created a user form that allows you to choose the item from a tiered drop down list and then loads a description of it into the cell.

So for example you choose "Cheese" (a food) and it returns "I love it!" You choose "Mice" (an animal) and it returns "Not so good!"

My question is, is there a way to group these seemingly unrelated items so that I don't have to type what to return for each individual item in my code?

Here is a sample of my code:

Private Sub CommandButton1_Click()
Dim rng As Range
Set rng = Selection
'rng.Value = Second.Value
If Second.Value = "Cheese" Then rng.Value = "I love it!"

End Sub


Private Sub Main_Change()
Dim index As Integer
index = Main.ListIndex

Second.Clear

Select Case index
Case Is = 0
With Second
.AddItem "Dog"
.AddItem "Cat"
.AddItem "Mouse"
End With
Case Is = 1
With Second
.AddItem "Cheese"
.AddItem "Pickles"
.AddItem "Hot Dogs"
End With
End Select
End Sub



Private Sub UserForm_Initialize()
With Main
.AddItem "Animals"
.AddItem "Food"
End With
End Sub

Thank you everybody
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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