Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Extract info based on Name | Excel Discussion (Misc queries) | |||
extract names based on conditions | Excel Discussion (Misc queries) | |||
How to extract multiple cells based on one value | Excel Worksheet Functions | |||
how to extract data based on date | Excel Worksheet Functions | |||
Extract row based on a criteria | Excel Programming |