Thread: strings
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Charlie Charlie is offline
external usenet poster
 
Posts: 703
Default strings

This might work:

Dim nAces As Long
Dim nCards As Long
Dim TestString As String
Dim Total As Long

nAces = 0
Total = 0
TestString = Replace(TestString, " ", "")
nCards = Len(TestString)

For i = 1 To nCards
If Mid(TestString, i, 1) = "A" Then nAces = nAces + 1
Next i

If nAces 1 Then
If nCards 3 Then
Total = nAces
For i = 1 To nCards
If Mid(TestString, i, 1) < "A" Then Total = Total +
Val(Mid(TestString, i, 1))
Next i
Else
' do something else
End If
End If


"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