Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default function for finding position of numeric character in a string

Hi,

Can anyone help with worksheet function for finding position of numeric
character in a string.

I am trying to extract data into the form 12a345 from data that may be like
any below:

12a345
12a345c
12a345_c
12ab345
12ab345c
12ab345_c

Extracting the first bit is easy with LEFT() but to extract the 345 I need
to find it's position in the string then I can use MID().


--
Regards,

Paul.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default function for finding position of numeric character in a string

Pop this code into your Personal workbook. It is a public function so you
will be able to access via =PERSONAL.XLS!FirstNumber(C5). It finds the firs
number in a string.

HTH

"Paul" wrote:

Hi,

Can anyone help with worksheet function for finding position of numeric
character in a string.

I am trying to extract data into the form 12a345 from data that may be like
any below:

12a345
12a345c
12a345_c
12ab345
12ab345c
12ab345_c

Extracting the first bit is easy with LEFT() but to extract the 345 I need
to find it's position in the string then I can use MID().


--
Regards,

Paul.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default function for finding position of numeric character in a string

Hi Paul,
This will find out what type of character is in each position. The problem
is that there is multiple "alpha" and multiple "numeric" positions in the
strings you have. I assumed the data was in column 1 and put a formula in B1
to find the character types and then put the results in an array. You can
querry the array for each type. I did not make an attempt to step down the
worksheet, but I don't think that is a substantial problem here. Somehow
IDing the first and last characters of each group of types is the real
problem. I am not even certain at this point exactly what you want extracted,
just the numeric portion of the code? If there is a consistant number of
"numerics" in a row, then I think it is possible to ID the beginning of each
group of numerics and this may come close to what you want.

Sub FindNum()
Dim z() As Variant
ActiveCell.FormulaR1C1 = "=LEN(RC[-1])"
TheLength = ActiveCell.Value
ReDim z(TheLength)
Ct1 = 0
CtEr = 0
For Position = 1 To TheLength
ActiveCell.FormulaR1C1 = "=VALUE(MID(RC[-1]," & (Words) & ",1))"
y = TypeName(ActiveCell.Value)
If y = "Error" Then
z(Words) = "Alpha"
Else
z(Words) = "Numeric"
End If
Next Position
Stop
End Sub


"Paul" wrote:

Hi,

Can anyone help with worksheet function for finding position of numeric
character in a string.

I am trying to extract data into the form 12a345 from data that may be like
any below:

12a345
12a345c
12a345_c
12ab345
12ab345c
12ab345_c

Extracting the first bit is easy with LEFT() but to extract the 345 I need
to find it's position in the string then I can use MID().


--
Regards,

Paul.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default function for finding position of numeric character in a string

Try this for the second group of numerics. Sorry for the first post, changed
some of the code, posed, but had not tested it.

Sub FindNum()
Dim z() As Variant
ActiveCell.FormulaR1C1 = "=LEN(RC[-1])"
TheLength = ActiveCell.Value
ReDim z(TheLength)
CtEr = 0
For Position = 1 To TheLength
ActiveCell.FormulaR1C1 = "=VALUE(MID(RC[-1]," & (Position) & ",1))"
y = TypeName(ActiveCell.Value)
If y = "Error" Then
z(Position) = "Alpha"
Else
z(Position) = "Numeric"
Ct1 = Ct1 + 1
If Ct1 = 3 Then SecondNumeric = Position
End If
Next Position
Stop
NumberToPull = Ct1 - 2
ActiveCell.FormulaR1C1 = "=VALUE(MID(RC[-1]," & (Ct1) & "," &
(NumberToPull) & "))"
End Sub

"Paul" wrote:

Hi,

Can anyone help with worksheet function for finding position of numeric
character in a string.

I am trying to extract data into the form 12a345 from data that may be like
any below:

12a345
12a345c
12a345_c
12ab345
12ab345c
12ab345_c

Extracting the first bit is easy with LEFT() but to extract the 345 I need
to find it's position in the string then I can use MID().


--
Regards,

Paul.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default function for finding position of numeric character in a string

Paul,
Try the following code adjusting the location (B2:B10) where your target
cells are as well as the destination should go:


Sub GetSting()
Dim strLeft As String
Dim strMid As String
Dim strRt As String

Dim oCell As Range
Dim Rng As Range
Dim i As Integer
Dim j As Integer

Set Rng = Range("B4:B10")
j = 4
For Each oCell In Rng
strLeft = Left(oCell, 2)
strMid = Mid(oCell, 3, 1)
For i = 1 To Len(oCell) - 3
If IsNumeric(Mid(oCell, j, 1)) Then
strRt = Mid(oCell, j, 3)
oCell.Offset(0, 1) = strLeft & strMid & strRt
GoTo NextCell
Else
j = j + 1
End If
Next i

NextCell:
Next oCell

End Sub

"Paul" wrote:

Hi,

Can anyone help with worksheet function for finding position of numeric
character in a string.

I am trying to extract data into the form 12a345 from data that may be like
any below:

12a345
12a345c
12a345_c
12ab345
12ab345c
12ab345_c

Extracting the first bit is easy with LEFT() but to extract the 345 I need
to find it's position in the string then I can use MID().


--
Regards,

Paul.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default function for finding position of numeric character in a string

Thanks to all.

I will try it ASAP.


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
return a character at a certain position in a string of text Miranda Excel Worksheet Functions 3 May 8th 23 11:46 AM
Finding a Character in a String Using VBA BVass Excel Discussion (Misc queries) 2 April 9th 09 03:52 AM
Finding a particular character in a string using VBA [email protected] Excel Programming 0 September 14th 04 04:16 PM
Finding a particular character in a string using VBA [email protected] Excel Programming 2 September 14th 04 05:55 AM
How find character position # in string from right end? Or how get range row num Ian Elliott[_3_] Excel Programming 1 December 17th 03 03:56 PM


All times are GMT +1. The time now is 10:40 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"