Ok so now you are happyish
I will tell you what I have done. It would have been pointless before.
Firstly did you see the uniquely sorted lists on the right of the data? Columns M to P inclusive?
Those are the values that I used to create the Data Validation Lists in rows 3 and 4, side stepping the need for ComboBoxes.
Lets focus on one of those lists.
M1 to M 5 Contains the following values:-
Manu
DH
KF
KM
PO
This is a Unique Sorted List based on the data in your column B.
The formula used is the array formula:
Formula:
=IFERROR(INDEX(Manu,MATCH(0,COUNTIF(Manu,"<" &Manu)-SUM(COUNTIF(Manu,M$1:M1)),0)),"")
Entered using Ctrl Shift Enter.
Manu
Refers to a Dynamic Named Range which will adjust to cope with the amount of data you have ie as you add more rows.
Select Formula, Name Manager and you will see that I have created 8 of these.
The formula for Manu is:-
Formula:
=INDIRECT("B5:B" & MATCH("zzz",Database!B$1:$B$20000,1))
This link is to a video that explains the above two formulas in great detail and a lot better than I could:-
https://www.youtube.com/watch?v=IZLAzIYfMDU
Manu2
Formula:
=INDIRECT("M2:M" & SUMPRODUCT(--(LEN(Database!M:M)>0),--(Database!M:M<>"")))
This returns M2:M5 which is the list I want to use for the data validation in B3
NB: This is a revised formula
This formula works too:
It is trial and error I am afraid
Formula:
=INDIRECT("M2:M" & SUM(--(LEN(Database!M1:M20000)>0)))
Similar formulas for all 4 Data Validations
Then I Selected Data Validation, selected from a list
And used the formula
Formula:
=Manu2
to tell excell what list to use.
Now for the Macros
The first and simplest macro is in the Database Sheet, it is therefore sheet specific.
Right Click on Database at the bottom of excel and select view code.
this code will be displayed:
Private Sub Worksheet_Change(ByVal Target As Range)
'This macro runs whenever a change is made on the sheet
'It is simply sorting your BTUs and your Blower Caps
If Range("F3").Value > Range("F4").Value Then
Temp = Range("F3").Value
Range("F3").Value = Range("F4").Value
Range("F4").Value = Temp
End If
If Range("K3").Value > Range("K4").Value Then
Temp = Range("K3").Value
Range("K3").Value = Range("K4").Value
Range("K4").Value = Temp
End If
End Sub
The Next Macro is also sheet specific but because I am using the tab as a macro button, it is more difficult to view.
Select the Developer tab and then visual basic.
Select view and then View and Project Explorer
Double Click on Sheet2(Search)
you should then see this code:-
I think it is self explanatory
Private Sub Worksheet_Activate()
Sheets("Database").Select
UserForm1.Show
End Sub
The final two Macros are in the userform.
You access then in the same way as the last macro.
Select the Developer tab and then visual basic.
Select view and then View and Project Explorer
Select the Userform
Double click on the userform
'This is the Crucial part
'It loads your listbox with the data matching your criteria
Private Sub UserForm_Activate()
'How many rows of data do you have?
LR = Cells(Rows.Count, 1).End(xlUp).Row
'Looking in Column B
With Columns("B:B")
'Find an entry Matching your Manufacturer
Set rngFind = .Find(Range("B3").Value, .Cells(1, 1), LookIn:=xlValues, lookat:=xlWhole)
If Not rngFind Is Nothing Then
strFirstAddress = rngFind.Address
Set rngPicked = rngFind
Do
'rngPicked is a list of cell references matching your manufacturer
Set rngPicked = Union(rngPicked, rngFind)
'find next matching cell
Set rngFind = .FindNext(rngFind)
'keep looping until you run out of cells of you get back to the first cell
Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstAddress
End If
End With
If strFirstAddress = "" Then Exit Sub
If strFirstAddress = "" Then Exit Sub
'This selects all matching cells.
rngPicked.Select
'This Loops Through all the cells and checks if all the criteria match
For Each c In Selection
If c.Row < 5 Then GoTo Skip
If Cells(c.Row, 2) <> Range("B3").Value Or Cells(c.Row, 5) <> Range("E3").Value Then GoTo Skip
If Cells(c.Row, 6) < Range("F3").Value Or Cells(c.Row, 6) > Range("F4").Value Then GoTo Skip
If Cells(c.Row, 11) < Range("K3").Value Or Cells(c.Row, 11) > Range("K4").Value Then GoTo Skip
'If it matches create a new entry and save the row number in column 1
ListBox1.AddItem c.Row
'Store the data from columns 2 to 6 in your data ( B to F)
For Count = 2 To 6
t = ListBox1.ListCount
ListBox1.List(ListBox1.ListCount - 1, Count - 1) = Cells(c.Row, Count).Value
Next
'Store the data from columns 8 to 11 in your data
For Count = 8 To 11
t = ListBox1.ListCount
ListBox1.List(ListBox1.ListCount - 1, Count - 2) = Cells(c.Row, Count).Value
Next
Skip:
Next
End Sub
The Last Macro is run when you select an entry on the listbox.
Private Sub ListBox1_Click()
'This returns the contents of column 1 of the list box, which is the row number on the database sheet
MyRow = ListBox1.Value
This writes Column 1 to the first line of the database
Range("A1").Value = MyRow
'Writes the next 5 columns
For Count = 2 To 6
Cells(1, Count).Value = Cells(MyRow, Count).Value
Next
Writes the last 4 columns
For Count = 8 To 11
Cells(1, Count).Value = Cells(MyRow, Count).Value
Next
Unload Me
End Sub
Bookmarks