airforceone
Board Regular
- Joined
- Feb 14, 2022
- Messages
- 214
- Office Version
- 2019
- 2016
- Platform
- Windows
Good day mate...
got the code from here Countifs Loop and been trying with my code but does not seem to work, does not give up any error but all result is zero (0).
my manual piece of code works but when applying the dynamic doesn't give the correct result
got the code from here Countifs Loop and been trying with my code but does not seem to work, does not give up any error but all result is zero (0).
my manual piece of code works but when applying the dynamic doesn't give the correct result
VBA Code:
Sub TerminateCount()
'https://www.mrexcel.com/board/threads/vba-countifs-with-loop.1086079/
Dim wsSource As Worksheet, wsTarget As Worksheet
Dim ctrX As Double, LRowSource As Double, LRowTarget As Double
Set wsSource = Sheets("SOURCE")
Set wsTarget = Sheets("Tally")
LRowSource = wsSource.Range("A" & Rows.count).End(xlUp).Row
LRowTarget = wsTarget.Range("A" & Rows.count).End(xlUp).Row
For ctrX = 2 To LRowTarget
'=COUNTIFS(Tally!$B$2:$B$34,$A2,Tally!$D$2:$D$34,$G$1)
wsTarget.Range("G2:G" & LRowTarget).Formula = WorksheetFunction.CountIfs( _
wsSource.Range("A2:A" & LRowSource), wsTarget.Cells(ctrX, "A"), wsSource.Range("C2:C" & LRowSource), "Male")
'=COUNTIFS(Tally!$B$2:$B$34,$A2,Tally!$C$2:$C$34,"<11")
wsTarget.Range("G2:G" & LRowTarget).Formula = WorksheetFunction.CountIfs( _
wsSource.Range("A2:A" & LRowSource), wsTarget.Cells(ctrX, "A"), wsSource.Range("B2:B" & LRowSource), "<11")
Next
' Debug.Print "LRowSource : " & LRowSource & " / LRowTarget : " & LRowTarget
End Sub
ANIMAL | AGE | SEX |
BAT | 55 | Female |
BAT | 36 | Male |
BAT | 36 | Male |
BAT | 49 | Male |
BIRD | 42 | Male |
BIRD | 47 | Male |
BIRD | 61 | Male |
BIRD | 63 | Male |
BIRD | 28 | Male |
BIRD | 31 | Male |
BIRD | 35 | Male |
BIRD | 24 | Male |
BIRD | 45 | Male |
BIRD | 39 | Female |
BIRD | 8 | Male |
BIRD | 24 | Female |
BIRD | 48 | Male |
BIRD | 66 | Male |
BIRD | 54 | Female |
BIRD | 66 | Male |
BIRD | 17 | Male |
BIRD | 18 | Male |
BIRD | 22 | Male |
BIRD | 2 | Male |
BIRD | 46 | Female |
BIRD | 43 | Female |
BIRD | 18 | Male |
BIRD | 49 | Male |
BIRD | 15 | Female |
BIRD | 11 | Female |
BIRD | 24 | Female |
BIRD | 35 | Male |
BIRD | 74 | Male |
BIRD | 40 | Male |
BIRD | 20 | Male |
BIRD | 58 | Male |
BIRD | 51 | Female |
BIRD | 21 | Female |
BIRD | 28 | Female |
BIRD | 29 | Male |
BIRD | 52 | Male |
BIRD | 29 | Female |
BIRD | 30 | Male |
BIRD | 39 | Male |
BIRD | 19 | Female |
BIRD | 21 | Male |
BIRD | 42 | Male |
BIRD | 19 | Female |
BIRD | 33 | Male |
BIRD | 7 | Male |
BIRD | 34 | Male |
BIRD | 25 | Male |
BIRD | 66 | Male |
BIRD | 41 | Male |
BIRD | 33 | Male |
BIRD | 64 | Female |
BIRD | 37 | Male |
BIRD | 29 | Male |
BIRD | 28 | Female |
BIRD | 20 | Male |
BIRD | 46 | Female |
BIRD | 34 | Male |
BIRD | 41 | Male |
BIRD | 78 | Female |
BIRD | 43 | Male |
BIRD | 7 | Male |
BIRD | 42 | Female |
BIRD | 41 | Female |
BIRD | 21 | Male |
BIRD | 29 | Male |
BIRD | 62 | Male |
BIRD | 59 | Male |
BIRD | 22 | Male |
BIRD | 28 | Male |
BIRD | 50 | Male |
BIRD | 29 | Male |
BIRD | 22 | Male |
BIRD | 39 | Male |
BIRD | 35 | Female |
BIRD | 46 | Male |
BIRD | 7 | Male |
BIRD | 35 | Male |
BIRD | 18 | Female |
BIRD | 65 | Female |
BIRD | 18 | Male |
BIRD | 58 | Female |
BIRD | 19 | Female |
BIRD | 57 | Male |
BIRD | 3 | Male |
BIRD | 25 | Male |
BIRD | 31 | Male |
BIRD | 3 | Male |
BIRD | 45 | Female |
BIRD | 42 | Female |
BIRD | 17 | Male |
BIRD | 54 | Male |
BIRD | 12 | Female |
BIRD | 32 | Female |
BIRD | 25 | Female |
BIRD | 26 | Male |
BIRD | 26 | Female |
BIRD | 46 | Female |
BIRD | 33 | Male |
BIRD | 43 | Male |
BIRD | 36 | Female |
BIRD | 32 | Male |
BIRD | 34 | Female |
BIRD | 28 | Male |
BIRD | 23 | Female |
BIRD | 47 | Male |
BIRD | 28 | Female |
BIRD | 10 months old | Female |
BIRD | 9 | Female |
BIRD | 8 | Male |
BIRD | 54 | Male |
BIRD | 36 | Male |
BIRD | 24 | Male |
BIRD | 14 | Male |
BIRD | 15 | Male |
BIRD | 10 | Female |
BIRD | 8 | Female |
BIRD | 32 | Female |
BIRD | 29 | Male |
BIRD | 11 | Male |
BIRD | 17 | Male |
BIRD | 35 | Male |
BIRD | 31 | Female |
BIRD | 52 | Male |
BIRD | 53 | Female |
BIRD | 5 | Male |
BIRD | 44 | Male |
BIRD | 21 | Male |
BIRD | 24 | Male |
BIRD | 56 | Male |
BIRD | 14 | Male |
BIRD | 0 | Female |
BIRD | 27 | Female |
BIRD | 0 | Female |
BIRD | 67 | Male |
BIRD | 46 | Male |
BIRD | 60 | Male |
BIRD | 36 | Male |
BIRD | 31 | Female |
BIRD | 51 | Male |
BIRD | 44 | Male |
BIRD | 57 | Male |
BIRD | 50 | Male |
BIRD | 56 | Female |
BIRD | 87 | Female |
BIRD | 75 | Male |
BIRD | 71 | Female |
BIRD | 21 | Male |
BIRD | 68 | Male |
BIRD | 21 | Male |
BIRD | 22 | Male |
BIRD | 56 | Male |
BIRD | 52 | Male |
BIRD | 54 | Female |
BIRD | 31 | Female |
BIRD | 24 | Male |
BIRD | 24 | Male |
BIRD | 27 | Male |
BIRD | 21 | Male |
BIRD | 34 | Male |
BIRD | 46 | Male |
BIRD | 46 | Female |
BIRD | 19 | Female |
BIRD | 45 | Female |
BIRD | 29 | Male |
BIRD | 25 | Male |
BIRD | 41 | Male |
BIRD | 13 | Female |
BIRD | 24 | Female |
BIRD | 17 | Male |
BIRD | 25 | Male |
BIRD | 21 | Female |
BIRD | 11 | Female |
BIRD | 39 | Female |
BIRD | 35 | Male |
BIRD | 70 | Female |
BIRD | 2 | Female |
BIRD | 37 | Female |
BIRD | 31 | Male |
BIRD | 28 | Female |
BIRD | 16 | Female |
BIRD | 82 | Male |
BIRD | 20 | Male |
BIRD | 32 | Female |
BIRD | 42 | Male |
BIRD | 39 | Female |
BIRD | 56 | Male |
BIRD | 21 | Male |
BIRD | 66 | Male |
BIRD | 53 | Female |
BIRD | 28 | Male |
BIRD | 26 | Male |
BIRD | 27 | Male |
BIRD | 38 | Male |
BIRD | 19 | Male |
BIRD | 21 | Male |
BIRD | 46 | Male |
BIRD | 75 | Female |
CAT | 74 | Female |
CAT | 49 | Male |
CAT | 18 | Male |
CAT | 18 | Male |
CAT | 43 | Female |
CAT | 22 | Male |
CAT | 15 | Female |
CAT | 2 | Male |
CAT | 46 | Female |
CAT | 69 | Female |
CAT | 21 | Male |
DOG | 42 | Male |
DOG | 47 | Male |
DOG | 61 | Male |
DOG | 45 | Male |
DOG | 67 | Male |
DOG | 63 | Male |
DOG | 31 | Male |
DOG | 28 | Male |
DOG | 35 | Male |
DOG | 24 | Male |
DOG | 45 | Male |
DOG | 39 | Female |
DOG | 8 | Male |
DOG | 48 | Male |
DOG | 24 | Female |
DOG | 66 | Male |
DOG | 54 | Female |
DOG | 17 | Male |
DOG | 66 | Male |
DOG | 50 | Male |
DOG | 36 | Male |
DOG | 49 | Male |
DOG | 2 | Male |
DOG | 46 | Female |
DOG | 22 | Male |
DOG | 15 | Female |
DOG | 43 | Female |
DOG | 18 | Male |
DOG | 18 | Male |
DOG | 11 | Female |
DOG | 35 | Male |
DOG | 24 | Female |
DOG | 74 | Male |
DOG | 48 | Male |
DOG | 40 | Male |
DOG | 44 | Male |
DOG | 34 | Male |
DOG | 58 | Male |
DOG | 20 | Male |
DOG | 44 | Male |
DOG | 21 | Female |
DOG | 51 | Female |
DOG | 28 | Female |
DOG | 52 | Male |
DOG | 29 | Male |
DOG | 29 | Female |
DOG | 30 | Male |
DOG | 39 | Male |
DOG | 58 | Male |
DOG | 69 | Male |
DOG | 32 | Male |
DOG | 19 | Female |
DOG | 21 | Male |
DOG | 42 | Male |
DOG | 19 | Female |
DOG | 33 | Male |
DOG | 48 | Female |
DOG | 7 | Male |
DOG | 34 | Male |
DOG | 25 | Male |
DOG | 66 | Male |
DOG | 36 | Male |
DOG | 33 | Male |
DOG | 60 | Male |
DOG | 41 | Male |
DOG | 33 | Male |
DOG | 64 | Female |
DOG | 24 | Female |
DOG | 37 | Male |
DOG | 20 | Male |
DOG | 29 | Male |
DOG | 28 | Female |
DOG | 46 | Female |
DOG | 34 | Male |
DOG | 51 | Male |
DOG | 48 | Male |
DOG | 41 | Male |
DOG | 78 | Female |
DOG | 43 | Male |
DOG | 41 | Female |
DOG | 7 | Male |
DOG | 42 | Female |
DOG | 32 | Female |
DOG | 21 | Male |
DOG | 29 | Male |
DOG | 46 | Male |
DOG | 62 | Male |
DOG | 59 | Male |
DOG | 28 | Male |
DOG | 22 | Male |
DOG | 50 | Male |
DOG | 29 | Male |
DOG | 22 | Male |
DOG | 39 | Male |
DOG | 35 | Female |
DOG | 39 | Male |
DOG | 46 | Male |
DOG | 7 | Male |
DOG | 46 | Male |
DOG | 65 | Female |
DOG | 34 | Female |
DOG | 28 | Male |
DOG | 35 | Male |
DOG | 52 | Male |
DOG | 34 | Male |
DOG | 18 | Female |
DOG | 18 | Male |
DOG | 65 | Female |
DOG | 29 | Male |
DOG | 57 | Male |
DOG | 3 | Male |
DOG | 58 | Female |
DOG | 19 | Female |
DOG | 25 | Male |
DOG | 31 | Male |
DOG | 42 | Female |
DOG | 45 | Female |
DOG | 3 | Male |
DOG | 17 | Male |
DOG | 54 | Male |
DOG | 40 | Male |
DOG | 32 | Female |
DOG | 25 | Female |
DOG | 12 | Female |
DOG | 43 | Male |
DOG | 44 | Male |
DOG | 26 | Male |
DOG | 26 | Female |
DOG | 26 | Male |
DOG | 33 | Male |
DOG | 46 | Female |
DOG | 32 | Male |
DOG | 43 | Male |
DOG | 36 | Female |
DOG | 34 | Female |
DOG | 28 | Male |
DOG | 23 | Female |
DOG | 48 | Female |
DOG | 47 | Male |
DOG | 54 | Male |
DOG | 8 | Male |
DOG | 9 | Female |
DOG | 28 | Female |
DOG | 10 months old | Female |
DOG | 24 | Male |
DOG | 36 | Male |
DOG | 15 | Male |
DOG | 10 | Female |
DOG | 14 | Male |
DOG | 42 | Female |
DOG | 34 | Male |
DOG | 30 | Male |
DOG | 32 | Female |
DOG | 11 | Male |
DOG | 29 | Male |
DOG | 8 | Female |
DOG | 17 | Male |
DOG | 35 | Male |
DOG | 5 | Male |
DOG | 31 | Female |
DOG | 52 | Male |
DOG | 53 | Female |
DOG | 44 | Male |
DOG | 21 | Male |
DOG | 24 | Male |
DOG | 29 | Male |
DOG | 56 | Male |
DOG | 39 | Male |
DOG | 0 | Female |
DOG | 0 | Female |
DOG | 27 | Female |
DOG | 14 | Male |
DOG | 67 | Male |
DOG | 46 | Male |
DOG | 47 | Male |
DOG | 36 | Male |
DOG | 31 | Female |
DOG | 37 | Male |
DOG | 29 | Male |
DOG | 51 | Male |
DOG | 30 | Male |
DOG | 44 | Male |
DOG | 35 | Male |
DOG | 57 | Male |
DOG | 50 | Male |
DOG | 40 | Female |
DOG | 45 | Male |
DOG | 26 | Male |
DOG | 71 | Female |
DOG | 87 | Female |
DOG | 56 | Female |
DOG | 75 | Male |
DOG | 21 | Male |
DOG | 68 | Male |
DOG | 21 | Male |
DOG | 22 | Male |
DOG | 58 | Male |
DOG | 55 | Male |
DOG | 56 | Male |
DOG | 52 | Male |
DOG | 61 | Male |
DOG | 35 | Male |
DOG | 63 | Female |
DOG | 57 | Male |
DOG | 54 | Female |
DOG | 31 | Female |
DOG | 24 | Male |
DOG | 24 | Male |
DOG | 21 | Male |
DOG | 57 | Female |
DOG | 21 | Male |
DOG | 27 | Male |
DOG | 36 | Male |
DOG | 23 | Male |
DOG | 43 | Male |
DOG | 24 | Male |
DOG | 21 | Male |
DOG | 34 | Male |
DOG | 19 | Female |
DOG | 46 | Male |
DOG | 46 | Female |
DOG | 45 | Female |
DOG | 45 | Male |
DOG | 29 | Male |
DOG | 30 | Male |
DOG | 25 | Male |
DOG | 13 | Female |
DOG | 41 | Male |
DOG | 24 | Female |
DOG | 17 | Male |
DOG | 11 | Female |
DOG | 25 | Male |
DOG | 21 | Female |
DOG | 39 | Female |
DOG | 35 | Male |
DOG | 70 | Female |
DOG | 37 | Female |
DOG | 31 | Male |
DOG | 2 | Female |
DOG | 28 | Female |
DOG | 16 | Female |
DOG | 82 | Male |
DOG | 42 | Male |
DOG | 20 | Male |
DOG | 32 | Female |
DOG | 39 | Female |
DOG | 56 | Male |
DOG | 66 | Male |
DOG | 21 | Male |
DOG | 53 | Female |
DOG | 26 | Male |
DOG | 28 | Male |
DOG | 27 | Male |
DOG | 30 | Female |
DOG | 31 | Male |
DOG | 19 | Male |
DOG | 38 | Male |
DOG | 55 | Male |
DOG | 21 | Male |
DOG | 46 | Male |
DOG | 48 | Female |
HORSE | 32 | Male |
HORSE | 45 | Male |
HORSE | 41 | Male |
HORSE | 34 | Male |
HORSE | 34 | Male |
HORSE | 37 | Male |
HORSE | 42 | Male |
HORSE | 33 | Male |
HORSE | 45 | Male |
HORSE | 45 | Male |
HORSE | 45 | Male |
HORSE | 45 | Male |
HORSE | 45 | Male |
HORSE | 34 | Male |
HORSE | 41 | Male |
HORSE | 37 | Male |
HORSE | 33 | Male |
HORSE | 39 | Male |
HORSE | 42 | Male |
HORSE | 32 | Male |
HORSE | 32 | Male |
HORSE | 34 | Male |
HORSE | 34 | Male |
HORSE | 42 | Male |
HORSE | 37 | Male |
HORSE | 33 | Male |
HORSE | 34 | Male |
HORSE | 39 | Male |
HORSE | 32 | Male |
HORSE | 32 | Male |
HORSE | 33 | Male |
HORSE | 33 | Male |
HORSE | 33 | Male |
HORSE | 33 | Male |
HORSE | 37 | Male |
HORSE | 42 | Male |
HORSE | 34 | Male |
HORSE | 39 | Male |
HORSE | 42 | Male |
HORSE | 42 | Male |
HORSE | 52 | Male |
HORSE | 52 | Male |
HORSE | 38 | Male |
HORSE | 41 | Male |
HORSE | 37 | Male |
HORSE | 34 | Male |
HORSE | 33 | Male |
HORSE | 42 | Male |
HORSE | 33 | Male |
HORSE | 33 | Male |
HORSE | 40 | Male |
HORSE | 42 | Male |
HORSE | 35 | Male |
HORSE | 33 | Male |
HORSE | 35 | Male |
HORSE | 34 | Female |
HORSE | 42 | Male |
HORSE | 43 | Male |
HORSE | 37 | Male |
HORSE | 39 | Male |
HORSE | 41 | Male |
MICE | 13 | Female |
MICE | 16 | Male |
MICE | 16 | Male |
MICE | 17 | Male |
MICE | 17 | Male |
ANIMAL | Male | Female | 1-10 | 11-20 |
BAT | ||||
BIRD | ||||
CAT | ||||
DOG | ||||
HORSE | ||||
MICE | ||||