Option Explicit
Dim rSource As Range
Dim lFld As Long
Dim lFld1 As Long
Dim oCtrl As MSForms.Control
Dim sCrit As String
Private Sub ComboBox3_Change()
'Select combobox value
sCrit = Me.ComboBox3.value
lFld = 5
lFld1 = 3
End Sub
Private Sub ComboBox4_Change()
'Select combobox value
sCrit = Me.ComboBox4.value
lFld = 10
lFld1 = 4
End Sub
Private Sub ComboBox5_Change()
'Select combobox value
sCrit = Me.ComboBox5.value
lFld = 23
lFld1 = 6
End Sub
Private Sub CommandButton1_Click()
Dim rdata As Range
Dim rdata1 As Range
Dim cell As Range
With Worksheets("Current Tooling List")
Set rdata = .Range(.Cells(1, 1), .Cells(.Rows.Count, 24).End(xlUp))
If Not .AutoFilterMode Then .Cells(1, 1).AutoFilter
.Cells(1, 1).AutoFilter Field:=lFld, Criteria1:=sCrit
On Error Resume Next
Set rSource = .AutoFilter.Range.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
.Cells(1, 200).CurrentRegion.ClearContents
rSource.Copy .Cells(1, 200)
Set rSource = .Cells(2, 200).CurrentRegion
Set rSource = rSource.Offset(1, 0).Resize(rSource.Rows.Count - 1, _
rSource.Columns.Count)
End With
With Worksheets("Filtered data view")
Set rdata1 = .Range(.Cells(1, 1), .Cells(.Rows.Count, 7).End(xlUp))
If Not .AutoFilterMode Then .Cells(1, 1).AutoFilter
.Cells(1, 1).AutoFilter Field:=lFld1, Criteria1:=sCrit
On Error Resume Next
Set rSource = .AutoFilter.Range.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
.Cells(1, 200).CurrentRegion.ClearContents
rSource.Copy .Cells(1, 200)
Set rSource = .Cells(2, 200).CurrentRegion
Set rSource = rSource.Offset(1, 0).Resize(rSource.Rows.Count - 1, _
rSource.Columns.Count)
End With
With Me.ListBox1
.RowSource = ""
.RowSource = rSource.Address(external:=True)
End With
End Sub
Private Sub CommandButton2_Click()
UndoFilter
UserForm_Initialize
End Sub
Private Sub CommandButton4_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
'Dim rCombo1 As Range
'Dim rCombo2 As Range
Dim rCombo3 As Range
Dim rCombo4 As Range
Dim rCombo5 As Range
Dim col As Long
Dim col2 As Long
Dim LastRw As Long
Application.ScreenUpdating = False
With Worksheets("Filtered data view")
LastRw = .UsedRange.Rows.Count
'create unique lists for combos using advanced filter
Range("IM:IV").EntireColumn.ClearContents
For col = 1 To 6
col2 = Choose(col, 248, 250, 252, 254, 256, 258)
.Range(.Cells(1, col), .Cells(LastRw, col)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, col2), Unique:=True
Next col
Set rSource = .Range(.Cells(2, 1), .Cells(LastRw, 6))
'Set rCombo1 = .Range(.Cells(2, 248), .Cells(.Rows.Count, 248).End(xlUp))
'Set rCombo2 = .Range(.Cells(2, 250), .Cells(.Rows.Count, 250).End(xlUp))
Set rCombo3 = .Range(.Cells(2, 252), .Cells(.Rows.Count, 252).End(xlUp))
Set rCombo4 = .Range(.Cells(2, 254), .Cells(.Rows.Count, 254).End(xlUp))
Set rCombo5 = .Range(.Cells(2, 258), .Cells(.Rows.Count, 258).End(xlUp))
With Me
.ListBox1.RowSource = rSource.Address(external:=True)
'.ComboBox1.RowSource = rCombo1.Address(external:=True)
'.ComboBox2.RowSource = rCombo2.Address(external:=True)
.ComboBox3.RowSource = rCombo3.Address(external:=True)
.ComboBox4.RowSource = rCombo4.Address(external:=True)
.ComboBox5.RowSource = rCombo5.Address(external:=True)
End With
For Each oCtrl In Me.Controls
If TypeOf oCtrl Is MSForms.ComboBox Then oCtrl.ListIndex = -1
Next oCtrl
End With
'Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
End Sub
Private Sub UndoFilter()
Dim rCombo3 As Range
Dim rCombo4 As Range
Dim rCombo5 As Range
Dim col As Long
Dim col2 As Long
Dim LastRw As Long
With Worksheets("Current Tooling List")
LastRw = .UsedRange.Rows.Count
'create unique lists for combos using advanced filter
Range("IM:IV").EntireColumn.ClearContents
For col = 1 To 6
col2 = Choose(col, 248, 250, 252, 254, 256, 258)
.Range(.Cells(1, col), .Cells(LastRw, col)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, col2), Unique:=True
Next col
Set rSource = .Range(.Cells(2, 1), .Cells(LastRw, 6))
'Set rCombo1 = .Range(.Cells(2, 248), .Cells(.Rows.Count, 248).End(xlUp))
'Set rCombo2 = .Range(.Cells(2, 250), .Cells(.Rows.Count, 250).End(xlUp))
Set rCombo3 = .Range(.Cells(2, 252), .Cells(.Rows.Count, 252).End(xlUp))
Set rCombo4 = .Range(.Cells(2, 254), .Cells(.Rows.Count, 254).End(xlUp))
Set rCombo5 = .Range(.Cells(2, 258), .Cells(.Rows.Count, 258).End(xlUp))
With Me
.ListBox1.RowSource = rSource.Address(external:=True)
'.ComboBox1.RowSource = rCombo1.Address(external:=True)
'.ComboBox2.RowSource = rCombo2.Address(external:=True)
.ComboBox3.RowSource = rCombo3.Address(external:=True)
.ComboBox4.RowSource = rCombo4.Address(external:=True)
.ComboBox5.RowSource = rCombo5.Address(external:=True)
End With
For Each oCtrl In Me.Controls
If TypeOf oCtrl Is MSForms.ComboBox Then oCtrl.ListIndex = -1
Next oCtrl
End With
Application.ScreenUpdating = True
End Sub
Bookmarks