Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Pulling apart a string

I have cells that look like so...

SS600S162-43
SS1100S162-43

I need to Pull the 600 or 1100 out of the string.

The string will always look like

Letter *** Letter *** 3-4 #'s *** Letter *** Letter *** ###-##

I need to pull the 3-4#'s out of the middle of it for use.

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Pulling apart a string

Here is a formula which evaluates Cell A1 and returns the middle 3 or 4
digits...

=IF(ISNUMBER(VALUE(MID(A1,6,1))), VALUE(MID(A1,3,4)),VALUE(MID(A1,3,3)))
--
HTH...

Jim Thomlinson


"Kevin O'Neill" wrote:

I have cells that look like so...

SS600S162-43
SS1100S162-43

I need to Pull the 600 or 1100 out of the string.

The string will always look like

Letter *** Letter *** 3-4 #'s *** Letter *** Letter *** ###-##

I need to pull the 3-4#'s out of the middle of it for use.

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Pulling apart a string

Wow very nice. Can that be translated into VBA? If not it is still OK,
I can probally work around it. Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Pulling apart a string

NM, Jim, thanks, works very well.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Pulling apart a string

Sorry. I got busy doing my job... :-)

Here is the code...

Sub test()
MsgBox FindDigits("SS600S162-43")
MsgBox FindDigits("SS1100S162-43")

End Sub

Public Function FindDigits(ByVal strInput As String) As Integer
If IsNumeric(Mid(strInput, 6, 1)) Then
FindDigits = CInt(Mid(strInput, 3, 4))
Else
FindDigits = CInt(Mid(strInput, 3, 3))
End If

End Function

--
HTH...

Jim Thomlinson


"Kevin O'Neill" wrote:

Wow very nice. Can that be translated into VBA? If not it is still OK,
I can probally work around it. Thanks.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Pulling apart a string

On 5 Jan 2006 13:25:09 -0800, "Kevin O'Neill" wrote:

I have cells that look like so...

SS600S162-43
SS1100S162-43

I need to Pull the 600 or 1100 out of the string.

The string will always look like

Letter *** Letter *** 3-4 #'s *** Letter *** Letter *** ###-##

I need to pull the 3-4#'s out of the middle of it for use.

Thanks.


This should give you the technique:
====================
Sub prn()
Const str1 As String = "SS600S162 - 43"
Const str2 As String = "SS1100S162 - 43"

Debug.Print Val(Mid(str1, 3, 255))
Debug.Print Val(Mid(str2, 3, 255))

End Sub
===================
600
1100
===================

The '255' for the number of characters in the Mid function is just any number
that is large enough to include all the numbers. In this case, it could be as
small as '4'.

The method takes advantage of the fact that the Val function stops evaluating
the string once it gets to a non-digit value.


--ron
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Pulling apart a string

Ah interesting, I'll keep that in mind, thanks guys.

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
pulling certain characters from a string of text SaraMack Excel Discussion (Misc queries) 3 December 10th 09 08:22 PM
string manipulation, pulling out last name from column [email protected] Excel Worksheet Functions 7 May 4th 08 01:45 AM
Pulling Year from a text string Elkar Excel Worksheet Functions 0 February 20th 07 06:33 PM
URL string, pulling in Stock Data William Benson[_2_] Excel Programming 0 July 15th 05 05:08 AM
pulling characters out of a string Patrick Excel Worksheet Functions 3 November 12th 04 06:58 PM


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

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

About Us

"It's about Microsoft Excel"