Link to home
Start Free TrialLog in
Avatar of tiehaze
tiehaze

asked on

Use vba to check total number of occurences

Here is a simplified version of what I am doing. Column A has different footnotes listed in each row:

S
S, L
@@, **

@
L
L
S

I need to count the total number or cells that has an L in it.  Any ideas?
Avatar of leonstryker
leonstryker
Flag of United States of America image

Try the COUNTIF function
Avatar of tiehaze
tiehaze

ASKER

How would I set up the criteria?
In column B next to each foot note put : =SEARCH("L",A1,1)

Then count column B values =COUNT(B:B)

If "L" is not in footnote the Search will display #VALUE and will not be counted by COUNT

Leon
Avatar of tiehaze

ASKER

Is there any other way of doing it within vba?
Avatar of tiehaze

ASKER

If not, that will work.
ASKER CERTIFIED SOLUTION
Avatar of leonstryker
leonstryker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In VBA code you will need to still use the same Array formula or you can loop through the range and use the Instr function

Leon
Avatar of tiehaze

ASKER

One minute, let me try some things out. I think I will be fine with the array.
Avatar of tiehaze

ASKER

The array did not work.  Can you try it out and see if you can figure it out?

{=COUNT(SEARCH("L",A1:A8,1))}

What are the outside brackets {} for? Do I need to keep those in there?
Type in the formula, then hit Cntrl/Shift/Enter keys at the same time.

This is a special type of Excel formula. You do not type in the brakets. Excel puts them there for you.

Leon