How to get sub strings using delimiter
Solved/Closed
Related:
- How to get sub strings using delimiter
- Programming: quotation marks, apostrophes and strings - Guide
3 responses
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
May 31, 2012 at 12:53 AM
May 31, 2012 at 12:53 AM
try this macro
result is in G1
result is in G1
Sub test() Dim j As Integer j = WorksheetFunction.Search(" ", Range("a1")) 'MsgBox j Range("G1") = Left(Range("a1"), j) End Sub
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jun 2, 2012 at 11:09 PM
Jun 2, 2012 at 11:09 PM
the sub string you are interested is
"crew2stg"
now see that there is a space before this sub string(and also this is the first space)
there is a space at the end of the sub string (which is second one)
use that to search
the macro is this and your value is x
you must always carefully study the macro and use it in your file
the full string is in A1 according to my macro
"crew2stg"
now see that there is a space before this sub string(and also this is the first space)
there is a space at the end of the sub string (which is second one)
use that to search
the macro is this and your value is x
you must always carefully study the macro and use it in your file
the full string is in A1 according to my macro
Sub test() Dim r As Range, j As Integer, k As Integer Dim x As String Set r = Range("A1") j = WorksheetFunction.Search(" ", r.Value) MsgBox j k = WorksheetFunction.Search(" ", r.Value, j + 1) MsgBox k x = Mid(r, j + 1, k - j) MsgBox x Range("G1") = x End Sub
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jun 1, 2012 at 02:39 AM
Jun 1, 2012 at 02:39 AM
In my file the full string is in A1. where is it yours ?
if it is not A1 changed range*"a1") in this line sutably
if it is not A1 changed range*"a1") in this line sutably
thanks a lot Venkat...its working perfect !!!
can u please also let me know the VB code if i want to copy the middle of the string.
I have the below string:
insert_job: crew2stg job_type: c
and now I want the substring "crew2stg"
I tried using MID, but its giving me "crew2stg job_type: c "
How can I get rid of the last part so that i get the desired sub string ?
can u please also let me know the VB code if i want to copy the middle of the string.
I have the below string:
insert_job: crew2stg job_type: c
and now I want the substring "crew2stg"
I tried using MID, but its giving me "crew2stg job_type: c "
How can I get rid of the last part so that i get the desired sub string ?
May 31, 2012 at 02:22 PM
j = WorksheetFunction.Search(" ", Range("a1"))