ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Extract based on Delimiters (https://www.excelbanter.com/excel-programming/348936-extract-based-delimiters.html)

ssjody

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


Jim Cone

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


Bob Phillips[_6_]

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





All times are GMT +1. The time now is 07:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com