Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi christopher ward:
i would do this: Dim linea As Integer linea = 2 do while <YourWorksheet.cells(linea,1).value <"" if (((chr(left(<YourWorksheet.cells(linea,1).value,1 ))=48) and (chr(left(<YourWorksheet.cells(linea,1).value,1)) <=57))or ((chr(left(<YourWorksheet.cells(linea,1).value,1) )=65)and (chr(left(<YourWorksheet.cells(linea,1).value,1)) =90))or ((chr(left(<YourWorksheet.cells(linea,1).value,1) )=97)and (chr(left(<YourWorksheet.cells(linea,1).value,1)) =122)))=true then do what you want End If linea = linea + 1 Loop this code check if the firt character is a 1-9, a-z, A-Z, and do something, add an else sentence to do other things if the first character is a symbol. I hope this would helpful for you, please let me know, Bye! |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi I will test your theory and come back to you - thank you for your time and
effort -- C Ward "luis_excelkid" wrote: Hi christopher ward: i would do this: Dim linea As Integer linea = 2 do while <YourWorksheet.cells(linea,1).value <"" if (((chr(left(<YourWorksheet.cells(linea,1).value,1 ))=48) and (chr(left(<YourWorksheet.cells(linea,1).value,1)) <=57))or ((chr(left(<YourWorksheet.cells(linea,1).value,1) )=65)and (chr(left(<YourWorksheet.cells(linea,1).value,1)) =90))or ((chr(left(<YourWorksheet.cells(linea,1).value,1) )=97)and (chr(left(<YourWorksheet.cells(linea,1).value,1)) =122)))=true then do what you want End If linea = linea + 1 Loop this code check if the firt character is a 1-9, a-z, A-Z, and do something, add an else sentence to do other things if the first character is a symbol. I hope this would helpful for you, please let me know, Bye! |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Okay, let's assume that the activecell is A1
Start by creating an Excel defined name (InsertNameDefine...), with a name of lenArray and a RefersTo value of =ROW(INDIRECT("1:"&LEN($A1))) Now use an array formula of =MID(A1,MIN(IF((ISNUMBER(MATCH(UPPER(MID(A1,lenArr ay,1)),CHAR(ROW(INDIRECT("65:90"))),0)))+(ISNUMBER (MATCH(--MID(A1,lenArray,1),ROW(INDIRECT("1:10"))-1,0))),lenArray)),1) which is an array formula, it should be committed with Ctrl-Shift-Enter, not just Enter. Excel will automatically enclose the formula in braces (curly brackets), do not try to do this manually. When editing the formula, it must again be array-entered. -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "christopher ward" wrote in message ... 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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
Public Function FirstAlphaNumeric(ByVal Text) As String Dim sTemp As String Dim sResult As String Dim i As Long sTemp = UCase(Text) If sTemp Like "*[0-9,A-Z]*" Then For i = 1 To Len(sTemp) sResult = Mid(sTemp, i, 1) If sResult Like "[0-9,A-Z]" Then Exit For Next i End If FirstAlphaNumeric = sResult End Function In article , 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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
range or string or long type | Excel Programming | |||
Determine data type in a string | Excel Programming | |||
Can I evaluate a function parameter(string type) as VBA souce code | Excel Programming | |||
testing for a string type | Excel Programming | |||
Type mismatch? string 2 a long?? | Excel Programming |