Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
Dim ws1 As Worksheet, ws2 As Worksheet, rng As Range, cel As Range, i As Long, sList1 As String, sList2 As String
Dim cCont As Control
Set ws1 = Worksheets("Data")
Set ws2 = Worksheets("Analysis")
sList1 = ""
sList2 = ""
If ListBox1.Selected(0) = True Then
sList1 = ""
Else
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
sList1 = sList1 & "|" & ListBox1.List(i)
End If
Next i
If sList1 = "" Then
sList1 = ""
ListBox1.Selected(0) = True
Else
sList1 = sList1 & "|"
End If
End If
If ListBox2.Selected(0) = True Then
sList2 = ""
Else
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) Then
sList2 = sList2 & "|" & ListBox2.List(i)
End If
Next i
If sList2 = "" Then
sList2 = ""
ListBox2.Selected(0) = True
Else
sList2 = sList2 & "|"
End If
End If
If ws2.UsedRange.Cells.Count > 1 Then ws2.UsedRange.Clear
ws1.[A1:AX1].Copy Destination:=ws2.[A16]
Set rng = ws1.Range(ws1.[A17], ws1.Cells(ws1.Rows.Count, "A").End(xlUp))
For Each cel In rng
If UCase(sList1) = "" Or InStr(sList1, "|" & cel.Value & "|") <> 0 Then
If UCase(sList2) = "" Or InStr(sList2, "|" & cel.Offset(0, 1).Value & "|") <> 0 Then
cel.Resize(1, 50).Copy Destination:=ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Offset(1)
End If
End If
Next cel
Unload Me
Application.ScreenUpdating = True
End Sub
Private Sub CommandButton4_Click()
Unload Me
End Sub
Private Sub UserForm1_Initialize()
ListBox1.Selected(0) = True
ListBox2.Selected(0) = True
End Sub
|