Count using VB

  • Thread starter Thread starter vedrah
  • Start date Start date
V

vedrah

How can I write a macro to count a series of text?
example x,y,z = 3
 
Hi
not quite sure but maybe
sub foo()
dim svalue as string
dim counter
svalue = "x,y,z"
counter = len(svalue) - len(replace(svalue,",","")) +1
msgbox counter
end sub
 
or maybe

Msgbox worksheetfunction.counta(Range("A1:H1"))

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Frank Kabel said:
Hi
not quite sure but maybe
sub foo()
dim svalue as string
dim counter
svalue = "x,y,z"
counter = len(svalue) - len(replace(svalue,",","")) +1
msgbox counter
end sub
 
thanks.

but it gets more complicated...
I have a series of text many x's , many y's and many z's.
So how do I count only the x's, y's and z's?

help......
 
Hi
you may first explain how you have stored these values?
- different cells
- in a single cell separated by comas
 
Hi Frank,

The data is arranged as follows:

x a
x b
x c
x d
y e
y f
y g
z h
z i
z j
z k
z l


how do i count items in column A.

hope u can help.

vedra
 
Hi
msgbox application.worksheetfunction.countif(Range("A1:A100"),"x")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top