Simon Leung
asked on
Search multi-criteria in VBA Excel
Is there a better way to match a multi-criteria for a cell simliar ot the code below in Excel ?
Thx
If Cells(i, 1) Like "win*" or Cells(i, 1) Like "linux*" or Cells(i, 1) Like "Unix*" Then
Worksheets("Sheet2").Cells(i, 5) = Cells(i, 1)
Thx
If Cells(i, 1) Like "win*" or Cells(i, 1) Like "linux*" or Cells(i, 1) Like "Unix*" Then
Worksheets("Sheet2").Cells(i, 5) = Cells(i, 1)
Or you can filter the data with this code which assumes the data starts in A2.
Sub ShowOS()
Dim lngLastRow As Long
With ActiveSheet
lngLastRow = .UsedRange.Rows.Count
.Columns("A:A").Select
Selection.AutoFilter
.Range("$A$2:$A$" & lngLastRow).AutoFilter Field:=1, Criteria1:="=Win*", _
Operator:=xlOr
.Range("$A$2:$A$" & lngLastRow).AutoFilter Field:=1, Criteria1:="=Lin*", _
Operator:=xlOr, Criteria2:="=Lin*"
.Range("$A$2:$A$" & lngLastRow).AutoFilter Field:=1, Criteria1:="=Uni*", _
Operator:=xlOr, Criteria2:="=Lin*"
End With
End Sub
ASKER
MultiCriteria.xlsm
Seem like Window can be sort out successfully. Beside, how to read back the input result
Seem like Window can be sort out successfully. Beside, how to read back the input result
Seem like Window can be sort out successfully. Beside, how to read back the input result
Can you elaborate further what's your requirement as well as the expected result?
ASKER
After running the macro, two cells with "Window" are also filter out.
AutoFilter only can put up to 2 filters if not wrong.
so you got to try the Array method instead. I will share this later.
so you got to try the Array method instead. I will share this later.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
or doing a loop with array will work too
Open in new window
then call it like:
Open in new window