Test for alpha char


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

New Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1  
Unread 18th September 2009, 23:54
miek's Avatar
miek
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Test for alpha char
     Excel: VBA   


------ Register to get rid of these "In Post" ads! ------

Category: Excel: VBA   

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

The Code Cage Advertisment
Advertisement
  #2  
Unread 19th September 2009, 00:42
Ron Rosenfeld's Avatar
Ron Rosenfeld
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Test for alpha char

------ Register to get rid of these "In Post" ads! ------


On Fri, 18 Sep 2009 15:53:01 -0700, miek <miek@discussions.microsoft.com>
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  
Unread 19th September 2009, 00:42
Chip Pearson's Avatar
Chip Pearson
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Test for alpha char

------ Register to get rid of these "In Post" ads! ------



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
<miek@discussions.microsoft.com> 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


The Code Cage Advertisment
Advertisement
  #4  
Unread 19th September 2009, 04:54
Rick Rothstein's Avatar
Rick Rothstein
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Test for alpha char

------ Register to get rid of these "In Post" ads! ------


> 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" <chip@cpearson.com> wrote in message
news:vc68b5p0kaj65fv9ipk430f36ts9uhfpu6@4ax.com...
>
> 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
> <miek@discussions.microsoft.com> 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



  #5  
Unread 19th September 2009, 12:11
Chip Pearson's Avatar
Chip Pearson
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Test for alpha char

------ Register to get rid of these "In Post" ads! ------


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"
<rick.newsNO.SPAM@NO.SPAMverizon.net> 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


  #6  
Unread 19th September 2009, 17:32
miek's Avatar
miek
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Test for alpha char

------ Register to get rid of these "In Post" ads! ------


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
>


The Code Cage Advertisment
Advertisement
  #7  
Unread 19th September 2009, 17:32
miek's Avatar
miek
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Test for alpha char

------ Register to get rid of these "In Post" ads! ------


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)



  #8  
Unread 19th September 2009, 19:13
Ron Rosenfeld's Avatar
Ron Rosenfeld
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Test for alpha char

------ Register to get rid of these "In Post" ads! ------


On Sat, 19 Sep 2009 09:28:01 -0700, miek <miek@discussions.microsoft.com>
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

The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

New Reply
The Code Cage at Facebookhe Code Cage at Twitter


Tags
alpha, char, test

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 08:59.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University