View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
christopher ward christopher ward is offline
external usenet poster
 
Posts: 59
Default How do I use VBA or a function to do a certain type of string

Guys

thanks for the swift response your answers all worked for my project and
will teach me to know my ASCII code set ( I used to but now i am old ). So
thanks for the time and effort
--
C Ward


"Paul Mathews" wrote:

Chris, you can try the following code (ascii codes 65-90 represent characters
A-Z, codes 97-122 represent characters a-z, codes 48-57 represent numbers
0-9):

Sub FindFirstAlphaNumeric()
Dim c As Range
Dim StrLen As Integer, i As Integer

For Each c In Range("A1:A100") 'modify data range according to your needs
StrLen = VBA.Len(c)
For i = 1 To StrLen
'Iterate through each string until alphanumeric character is
located...
If (Asc(VBA.Mid(c.Value, i, 1)) = 65 And _
Asc(VBA.Mid(c.Value, i, 1)) <= 90) Or _
(Asc(VBA.Mid(c.Value, i, 1)) = 97 And _
Asc(VBA.Mid(c.Value, i, 1)) <= 122) Or _
(Asc(VBA.Mid(c.Value, i, 1)) = 48 And _
Asc(VBA.Mid(c.Value, i, 1)) <= 57) Then
'...and write that character to the cell in the next column
c.Offset(0, 1).Value = VBA.Mid(c.Value, i, 1)
'exit string iteration for loop
Exit For
End If
Next i
Next c
End Sub


"christopher ward" wrote:

i have a simple spreadsheet of

christopher ward in cell A1
'''''''''''''''''brian wild in cell a2
####jane brown in cell a3
;;;;8888 in cell a4

I now need a VBA function or VBA code Macro that works out in each cell
where the first alphanumeric character falls and returns the character.The
length of the string is not fixed and will have various characters which are
not a-z or 1-9 which are the ones I am interested in.

If you reply to this post thanks in advance it is appreciated

so my answers would be

c
b
j
8


thanks
--
C Ward