Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Test for alpha char

I'm trying to test a string for alpha chars, if alpha char append char to a
new string
The following does not work. Is there a tweak I can apply?

l_Alpha_chars = "abcd1"
For q = 1 To Len(l_Alpha_chars)
l_chr = Mid(l_Alpha_chars, q, 1)
If l_chr = [a..z] Then
NewStr = NewStr & l_chr
End If
Next q
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Test for alpha char

On Fri, 18 Sep 2009 15:53:01 -0700, miek
wrote:

I'm trying to test a string for alpha chars, if alpha char append char to a
new string
The following does not work. Is there a tweak I can apply?

l_Alpha_chars = "abcd1"
For q = 1 To Len(l_Alpha_chars)
l_chr = Mid(l_Alpha_chars, q, 1)
If l_chr = [a..z] Then
NewStr = NewStr & l_chr
End If
Next q


For what you seem to be doing, using your technique:

===========================
Option Explicit
Sub bar()
Const l_Alpha_chars As String = "abcd1"
Dim l_chr As String
Dim NewStr As String
Dim q As Long

For q = 1 To Len(l_Alpha_chars)
l_chr = Mid(l_Alpha_chars, q, 1)
If l_chr Like "[a-z]" Then
NewStr = NewStr & l_chr
End If
Next q

Debug.Print NewStr

End Sub
==========================
--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Test for alpha char

Thank I had a syntax error

Was using: If l_chr = [a..z] Then
Now using: If l_chr Like "[a-z]" Then

Thanks again

"Ron Rosenfeld" wrote:

For what you seem to be doing, using your technique:

===========================
Option Explicit
Sub bar()
Const l_Alpha_chars As String = "abcd1"
Dim l_chr As String
Dim NewStr As String
Dim q As Long

For q = 1 To Len(l_Alpha_chars)
l_chr = Mid(l_Alpha_chars, q, 1)
If l_chr Like "[a-z]" Then
NewStr = NewStr & l_chr
End If
Next q

Debug.Print NewStr

End Sub
==========================
--ron

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Test for alpha char

On Sat, 19 Sep 2009 09:28:01 -0700, miek
wrote:

Thank I had a syntax error

Was using: If l_chr = [a..z] Then
Now using: If l_chr Like "[a-z]" Then

Thanks again



You're welcome.
--ron
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Test for alpha char


Try some code like the following:

Function IsCharAlpha(C As String) As Boolean
IsCharAlpha = UCase(Left(C, 1)) Like "[A-Z]"
End Function

Function IsStringAlpha(s As String) As Boolean
IsStringAlpha = _
(UCase(s) Like Application.WorksheetFunction.Rept("[A-Z]",
Len(s))) _
And _
Len(s) 0
End Function


The IsCharAlpha function tests if a single character C is alpha. The
IsStringAlpha functions tests if a string of characters S is alpha.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Fri, 18 Sep 2009 15:53:01 -0700, miek
wrote:

I'm trying to test a string for alpha chars, if alpha char append char to a
new string
The following does not work. Is there a tweak I can apply?

l_Alpha_chars = "abcd1"
For q = 1 To Len(l_Alpha_chars)
l_chr = Mid(l_Alpha_chars, q, 1)
If l_chr = [a..z] Then
NewStr = NewStr & l_chr
End If
Next q



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Test for alpha char

Function IsStringAlpha(s As String) As Boolean
IsStringAlpha = (UCase(s) Like Application.WorksheetFunction. _
Rept("[A-Z]", Len(s))) And Len(s) 0
End Function


This somewhat shorter function will do exactly what your function does...

Function IsStringAlpha(S As String) As Boolean
IsStringAlpha = Not S like "*[!A-Za-z]*" And Len(S) 0
End Function

--
Rick (MVP - Excel)


"Chip Pearson" wrote in message
...

Try some code like the following:

Function IsCharAlpha(C As String) As Boolean
IsCharAlpha = UCase(Left(C, 1)) Like "[A-Z]"
End Function

Function IsStringAlpha(s As String) As Boolean
IsStringAlpha = _
(UCase(s) Like Application.WorksheetFunction.Rept("[A-Z]",
Len(s))) _
And _
Len(s) 0
End Function


The IsCharAlpha function tests if a single character C is alpha. The
IsStringAlpha functions tests if a string of characters S is alpha.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Fri, 18 Sep 2009 15:53:01 -0700, miek
wrote:

I'm trying to test a string for alpha chars, if alpha char append char to
a
new string
The following does not work. Is there a tweak I can apply?

l_Alpha_chars = "abcd1"
For q = 1 To Len(l_Alpha_chars)
l_chr = Mid(l_Alpha_chars, q, 1)
If l_chr = [a..z] Then
NewStr = NewStr & l_chr
End If
Next q


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Test for alpha char

Yup, that's a better way. Thanks.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Fri, 18 Sep 2009 23:52:51 -0400, "Rick Rothstein"
wrote:

Function IsStringAlpha(s As String) As Boolean
IsStringAlpha = (UCase(s) Like Application.WorksheetFunction. _
Rept("[A-Z]", Len(s))) And Len(s) 0
End Function


This somewhat shorter function will do exactly what your function does...

Function IsStringAlpha(S As String) As Boolean
IsStringAlpha = Not S like "*[!A-Za-z]*" And Len(S) 0
End Function

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Test for alpha char

Thanks these functions are great help

"Chip Pearson" wrote:


Try some code like the following:

Function IsCharAlpha(C As String) As Boolean
IsCharAlpha = UCase(Left(C, 1)) Like "[A-Z]"
End Function

Function IsStringAlpha(s As String) As Boolean
IsStringAlpha = _
(UCase(s) Like Application.WorksheetFunction.Rept("[A-Z]",
Len(s))) _
And _
Len(s) 0
End Function


The IsCharAlpha function tests if a single character C is alpha. The
IsStringAlpha functions tests if a string of characters S is alpha.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula with alpha char in cell soni Excel Discussion (Misc queries) 7 January 9th 09 04:04 PM
Get "####" when use alpha char in a cell referenced by a formula Leo Excel Worksheet Functions 5 January 8th 09 06:18 PM
How do I make a cell allow only 24 alpha/num. char.to be entered Fred@JFK Excel Programming 1 November 2nd 06 02:45 PM
test if a character in a string is alpha Matilda Excel Programming 7 October 16th 06 02:36 PM
Test for char in string & separating if present Ken Loomis Excel Programming 5 October 7th 04 06:38 PM


All times are GMT +1. The time now is 04:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"