Maybe something like
Code:
Private Sub CommandButton1_Click()
Dim sp1, sp2
With Sheets("Pcode")
If .AutoFilterMode Then .AutoFilterMode = False
sp1 = Split(Me.ComboBox2, "-")
sp2 = Split(Me.ComboBox3, "-")
.Range("A1:Z1").AutoFilter 1, Me.ComboBox1.Value
If UBound(sp1) > 0 Then
.Range("A1:Z1").AutoFilter 2, ">=" & sp1(0), xlAnd, "<=" & sp1(1)
Else
.Range("A1:Z1").AutoFilter 2, sp1(0)
End If
If UBound(sp2) > 0 Then
.Range("A1:Z1").AutoFilter 3, ">=" & sp2(0), xlAnd, "<=" & sp2(1)
Else
.Range("A1:Z1").AutoFilter 3, sp2(0)
End If
If Not Evaluate("isref(Result!A1)") Then Sheets.Add(, Sheets(Sheets.Count)).name = "Result"
.AutoFilter.Range.Copy Sheets("Result").Range("A1")
.AutoFilterMode = False
End With
End Sub
Hi tried yours but it only copied the header cell (first row) and not the data found.
Private Sub CommandButton1_Click() Dim sp1, sp2, sp3
With Sheets("RORO")
If .AutoFilterMode Then .AutoFilterMode = False
sp1 = Split(Me.ComboBox2, "-")
sp2 = Split(Me.ComboBox3, "-")
sp3 = Split(Me.ComboBox4, "-")
.Range("A1:Z1").AutoFilter 1, Me.ComboBox1.Value
If UBound(sp1) > 19 Then
.Range("H1:H100").AutoFilter 2, ">=20" & sp1(0), xlAnd, "30<=" & sp1(1)
Else
.Range("H1:H100").AutoFilter 2, sp1(0)
End If
If UBound(sp2) > 59999 Then
.Range("M1:M100").AutoFilter 3, ">=10000" & sp2(0), xlAnd, "60000<=" & sp2(1)
Else
.Range("M1:M100").AutoFilter 3, sp2(0)
End If
If UBound(sp3) > 19 Then
.Range("O1:O100").AutoFilter 3, ">=20" & sp3(0), xlAnd, "30<=" & sp3(1)
Else
.Range("O1:O100").AutoFilter 3, sp3(0)
End If
If Not Evaluate("isref(Result!A2)") Then Sheets.Add(, Sheets(Sheets.Count)).Name = "Result"
.AutoFilter.Range.Copy Sheets("Result").Range("A2")
.AutoFilterMode = False
End With
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
For i = 1 To Sheets.Count
'Type Of Ship
ComboBox1.AddItem Sheets(i).Name
Next
'Crew
ComboBox2.List = Array("<20", "20-30", ">20")
'Gross Tonnage
ComboBox3.List = Array("<10000", "10000-60000", ">60000")
'Max speed
ComboBox4.List = Array("<20", "20-30", ">20")
End Sub