Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Extract based on Delimiters

On a Form I have a Combo Box that lists values like this
1.2.3.4
10.11.12.13
90.121.92.93
where the "." periods are my delimiter

I want to extract only the 1st two octets and write them to a
worksheet.

What code could I use to extract based on a delimiter? For example if I
pick the 1st example in my list, the 1.2 would be extracted and set as
the value to write to my worksheet. If the 2nd example was chosen,
10.11 would be written.

Any Ideas?

Jody

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Extract based on Delimiters

Jody,
Here is an idea...

'---------------------------------
Function FirstTwoSections(ByRef strInput As String)
'Returns the portion of a provided string that occurs before the
'second dot. If only one dot then entire string is returned.
'Jim Cone - San Francisco - USA - 12/26/2005.
Dim strResult As String
Dim lngLength As Long
Dim lngN As Long

lngLength = 0
For lngN = 1 To 2
lngLength = InStr(lngLength + 1, strInput, ".", vbTextCompare)
Next
If lngLength 0 Then
strResult = Left$(strInput, lngLength - 1)
Else
lngLength = InStr(1, strInput, ".", vbTextCompare)
If lngLength 0 Then
strResult = strInput
Else
strResult = "No dots "
End If
End If
FirstTwoSections = strResult
End Function


'Calls Function
Sub GetNumber()
Dim strFromCombo As String
strFromCombo = "1.22.333.444"
Msgbox FirstTwoSections(strFromCombo)
End Sub

'----------------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"ssjody" wrote in message
oups.com
On a Form I have a Combo Box that lists values like this
1.2.3.4
10.11.12.13
90.121.92.93
where the "." periods are my delimiter

I want to extract only the 1st two octets and write them to a
worksheet.
What code could I use to extract based on a delimiter? For example if I
pick the 1st example in my list, the 1.2 would be extracted and set as
the value to write to my worksheet. If the 2nd example was chosen,
10.11 would be written.
Any Ideas?
Jody

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Extract based on Delimiters

Try this

sTest = "10.11.12.13"

Debug.Print Left(sTest, InStr(InStr(sTest, ".") + 1, sTest, ".") - 1)


--

HTH

RP
(remove nothere from the email address if mailing direct)


"ssjody" wrote in message
oups.com...
On a Form I have a Combo Box that lists values like this
1.2.3.4
10.11.12.13
90.121.92.93
where the "." periods are my delimiter

I want to extract only the 1st two octets and write them to a
worksheet.

What code could I use to extract based on a delimiter? For example if I
pick the 1st example in my list, the 1.2 would be extracted and set as
the value to write to my worksheet. If the 2nd example was chosen,
10.11 would be written.

Any Ideas?

Jody



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
Extract info based on Name khers Excel Discussion (Misc queries) 4 July 25th 11 04:24 PM
extract names based on conditions Bobak Excel Discussion (Misc queries) 2 September 3rd 08 08:16 PM
How to extract multiple cells based on one value Extrer datos en excel Excel Worksheet Functions 0 April 12th 06 07:17 PM
how to extract data based on date vidhya Excel Worksheet Functions 1 October 18th 05 10:39 AM
Extract row based on a criteria Mah[_2_] Excel Programming 4 December 17th 03 06:05 PM


All times are GMT +1. The time now is 09:56 PM.

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"