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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,584
Messages
6,120,384
Members
448,956
Latest member
JPav

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