Thread: strings
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default strings

This pseudo code might help:

Teststring = Application.Trim(TestString)
if instr(1,teststring,"A",vbTextCompare) then
num = len(teststring)-len(replace(teststring,"A",""))
if num 1 then
s = Application.Replace(TestString," ","")
if instr(1,s,"AAAA",vbTextCompare) then
' greater than 3
s1 = Application.Replace(Ucase(TestString),"A","1")
s1 = Application.Replace(s1," ",",")
tot = Application.Evaluate("Sum(" & s1 & ")"
msgbox Tot
elseif instr(1,s,"AAA") then
' 3 only
else
' 2 only

end if
else
' 1 A's
end if
else
' No A's
s1 = Application.Replace(TestString," ",",")
tot = Evaluate("Sum(" & s1 & ")"
msgbox "No A's, Tot: " & tot
end if

your example of what to do when there are more than 3 A's

'A A 2 3 4' = 11

Only contains 2 A's.

--
Regards,
Tom Ogilvy

"RobcPettit" wrote:

Hi Im trying to ask questions of a string. My string is in "A1". I
assign it to 'teststring' which looks like "A 2 3 A 4" This can be
any combination with or without A or Numbers and contain 3 values upto
5. Id like to ask this of my string.
Does it contain "A", If yes How many....if more than 1 then....how many
values in string altogether.....if 3 go do something if three add the
numbers up in the string and use the A's as 1 eg 'A A 2 3 4' = 11.

Does it contain A, if no add al the values.

I could do with knowing the position of the A's but that a minor prob.
When I was doing this with 2 values I used If InStr("A", TestString)
0, as advised prev and this was great.
Hope this makes sense.
Regards Robert