Hi Team,
I want to filter Score greater than 40 Fifty's and greater than 25 Century.
Filter on Column C and D Data,
Expected Output are in Column Range("H2:j7") , how to use array to meet condition.
Below is attempted code only able to copy First Column
Below is a sample data with expected output.
Thanks
mg
I want to filter Score greater than 40 Fifty's and greater than 25 Century.
Filter on Column C and D Data,
Expected Output are in Column Range("H2:j7") , how to use array to meet condition.
Below is attempted code only able to copy First Column
VBA Code:
Sub FilterData()
Dim a As Variant, b As Variant
Dim i As Long, k As Long
With Sheets("Sheet1")
a = .Range("A2:D7").Value
End With
ReDim b(1 To UBound(a), 1 To 2)
For i = 1 To UBound(a)
If a(i, 3) > 40 And a(i, 4) > 25 Then 'Greater than 40 Fifty and Greater than 25 Century
k = k + 1
b(k, 1) = a(i, 1)' how to add remaning cells here
End If
Next i
If k > 0 Then Sheets("Sheet1").Range("h2").Resize(k).Value = b
End Sub
Below is a sample data with expected output.
Book6 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | |||
1 | Player Name | Country | Fifty | Century | Expected Output | "=====>" | Name | Country | Century | |||
2 | Sachin | India | 100 | 50 | Sachin | India | 50 | |||||
3 | Dhoni | India | 90 | 28 | Dhoni | India | 28 | |||||
4 | Ponting | Australia | 80 | 40 | Ponting | Australia | 40 | |||||
5 | Peterson | England | 100 | 25 | Gilchrist | Australia | 80 | |||||
6 | Gayle | West Indies | 40 | 32 | ||||||||
7 | Gilchrist | Australia | 65 | 80 | ||||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
I2:I5 | I2 | =VLOOKUP(H2,A1:$D$7,2,0) |
J2:J5 | J2 | =VLOOKUP(H2,$A$1:$D$7,4,0) |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
_FilterDatabase | =Sheet1!$A$1:$D$7 | I2:J2, J3:J5 |
Thanks
mg