Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a string "xxxx_yy_zzzzzz". I would like to store "xxxx" as a string in
a variable, "yy" as a string in another variable, and "zzzzzz" as a string in another variable. Is there code in visual basic for excel that would help me achieve this? Thanks Ahsan |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Ahsan
Is it always 4_2_6 characters Is there always a underscore between the text -- Regards Ron de Bruin http://www.rondebruin.nl "Ahsan" wrote in message ... I have a string "xxxx_yy_zzzzzz". I would like to store "xxxx" as a string in a variable, "yy" as a string in another variable, and "zzzzzz" as a string in another variable. Is there code in visual basic for excel that would help me achieve this? Thanks Ahsan |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Is it always going to be the same number of characters? You could use the
left$, mid$, and right$ functions. varstring = "xxxx_yy_zzzzzz" varx = left$(varstring,4) vary = mid$(varstring,6,2) varz = right$(varstring,6) Or you can use the split command. This will split the string based on a delimiter and store the values in an array. vararray = split(varstring, "_") Brian "Ahsan" wrote in message ... I have a string "xxxx_yy_zzzzzz". I would like to store "xxxx" as a string in a variable, "yy" as a string in another variable, and "zzzzzz" as a string in another variable. Is there code in visual basic for excel that would help me achieve this? Thanks Ahsan |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
As a side note, it doesn't have to be the same number of characters to use
the left, right, and mid functions, but you would have to do a bit more coding to find the location of the "_". The "instr" command will give you the position of the "_" character. "Brian K. Sheperd" wrote in message ... Is it always going to be the same number of characters? You could use the left$, mid$, and right$ functions. varstring = "xxxx_yy_zzzzzz" varx = left$(varstring,4) vary = mid$(varstring,6,2) varz = right$(varstring,6) Or you can use the split command. This will split the string based on a delimiter and store the values in an array. vararray = split(varstring, "_") Brian "Ahsan" wrote in message ... I have a string "xxxx_yy_zzzzzz". I would like to store "xxxx" as a string in a variable, "yy" as a string in another variable, and "zzzzzz" as a string in another variable. Is there code in visual basic for excel that would help me achieve this? Thanks Ahsan |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
Assuming: 1) _ is a delimeter 2) You're using Excel 2000+ You could use the Split function to create an array of three elements from your example. E.g., Sub yadda() Dim strArr() As String, i As Long Const myStr As String = "xxxx_yy_zzzzzz" Let strArr = Split(myStr, "_") For i = LBound(strArr) To UBound(strArr) Debug.Print strArr(i), Next End Sub Regards, Nate Oliver |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Selecting right part of text string | Excel Worksheet Functions | |||
Delete part of a text string | Excel Worksheet Functions | |||
Extract part of a text string | Excel Worksheet Functions | |||
Omitting right part of text string | Excel Worksheet Functions | |||
How do I extract part of a text string | Excel Discussion (Misc queries) |