VBA code to display data that meets criteria in another column.

MrNew

New Member
Joined
Jun 12, 2015
Messages
9
Hi If the answer is posted elsewhere then I apologise and please direct me, I have tried some similar answers but unable to get them to work with what I am trying to do.
I have a user form that opens where you first select from a drop down either Elec, Plumb or Build..(created as a named group on sheet1), this then displays in a second drop down the list of each group, i.e. if Elec is selected in dropdown 1 then Elec1, Elec2, Elec3 is displayed in drop down 2 and when one of these is selected the address etc. is displayed in remaining boxes.

This all works fine but Elec1, Elec2, etc. are only done as a group name off sheet1 and what I would like to do is have it so that when Elec is selected in drop down 1, drop down 2 displays everything from column 2 that has the tag of "E" in column 1, this way when I add to the list I just need to tag it with "E" or "B" etc and not keep extending the groupname.

Sheet 1 is as below Elec1, Elec2, Elec3 etc. is grouped with name Elec and same with Plumb1 etc.

ABCDE
1TagNameNumberAddressPost Code
2EElec 10844Address OnePC1
3EElec 20845Address TwoPC2
4EElec 30846Address ThreePC3
5PPlumb10847Address FourPC4
6PPlumb20848Address FivePC5
7PPlumb30849Address SixPC6
8BBuild10850Address SevenPC7
9BBuild20851Address EightPC8
10BBuild30852Address NinePC9
11
12
13Elec
14Plumb
15Build

<tbody>
</tbody>
<strike></strike>
The code on the UserForm is as follows:

Code:
 Private Sub ComboBox1_Change()
 Dim x As Integer
 x = ComboBox1.ListIndex


 Select Case x
 Case Is = 0
     ComboBox2.RowSource = "Elec"
 Case Is = 1
     ComboBox2.RowSource = "Plum"
 Case Is = 2
     ComboBox2.RowSource = "Build"
 End Select
 End Sub


 Private Sub ComboBox2_Change()
 Dim dd_name As String
 Dim Lookup_Range As Range
 Dim Name As Single


 dd_name = ComboBox2.Text


 Set Lookup_Range = Range("chart")
 Name = Application.WorksheetFunction.VLookup(dd_name, Lookup_Range, 2, False)
 Address = Application.WorksheetFunction.VLookup(dd_name, Lookup_Range, 3, False)
 Post_Code = Application.WorksheetFunction.VLookup(dd_name, Lookup_Range, 4, False)

 TextBox1.Text = Name
 TextBox2.Text = Address
 TextBox3.Text = Post_Code
 End Sub

 Private Sub CommandButton1_Click()
 ClearForm
 End Sub

I suppose what I am looking for is some way in which to say,
Select Case x
Case Is = 0
ComboBox2.RowSource = "Everything from column 2 where column 1 is E"
<strike></strike>Case Is = 1
ComboBox2.RowSource = "Everything from column 2 where column 1 is P"

I hope this makes sense.
<strike></strike>
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

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