# Thread: VBA to count Thanks: 0 Likes: 0

1. ## VBA to count

 c m brand 1 2 brand 4 1 brand 4 1 brand 1 3 brand 7 1

I need to count quantity of the brands , there are many brands numbers in the list.using new excel.
The result should be brand 1 = 5 brand 4 = 2 brand 7 = 1

Thanks !

2. ## Re: VBA to count

Hey,

=SUMPRODUCT((\$C\$2:\$C\$6="brand 1")*(\$M\$2:\$M\$6))

Assuming brand names in Col C (rows 2 - 6) & the quantity in Col M (rows 2 - 6)

NB: You can change "brand 1" to be more dynamic by making a cell as "brand 1" and referencing the cell.

3. ## Re: VBA to count

Another way
=SUMIF(C:C,"Brand1",M:M)

4. ## Re: VBA to count

Originally Posted by tyija1995
Hey,

=SUMPRODUCT((\$C\$2:\$C\$6="brand 1")*(\$M\$2:\$M\$6))

Assuming brand names in Col C (rows 2 - 6) & the quantity in Col M (rows 2 - 6)

NB: You can change "brand 1" to be more dynamic by making a cell as "brand 1" and referencing the cell.

I got error value.....
There are many brands i want to count isn't it possible not to type the brands ?

5. ## Re: VBA to count

Like

CDEFGHIJKLMNOP
2cm
3brand 12brand 15
4brand 41brand 42
5brand 41brand 71
6brand 13
7brand 71

Sheet1

Worksheet Formulas
CellFormula
P3=SUMIF(C:C,O3,M:M)

6. ## Re: VBA to count

Originally Posted by Fluff
Like

C D E F G H I J K L M N O P
2 c m
3 brand 1 2 brand 1 5
4 brand 4 1 brand 4 2
5 brand 4 1 brand 7 1
6 brand 1 3
7 brand 7 1
Sheet1

Worksheet Formulas
Cell Formula
P3 =SUMIF(C:C,O3,M:M)
Yes that's what i need but i get results of 0

7. ## Re: VBA to count

Are the quantities stored as Numbers?

It may be the case that they are Text or prefixed with an apostrophe - in which the formula @Fluff wrote will return 0 as you have said has happened

8. ## Re: VBA to count

Originally Posted by tyija1995
Are the quantities stored as Numbers?

It may be the case that they are Text or prefixed with an apostrophe - in which the formula @Fluff wrote will return 0 as you have said has happened
The quantity are numbers how can i solve this?

9. ## Re: VBA to count

Also make sure that your entries in columns C and O match EXACTLY.
Any extras spaces in one and not the other will cause it NOT to match, and return 0s.