![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Apr 2003
Location: Latvia
Posts: 56
|
Hi!
I have following problem, which i would be pleased to have help with. i have a cell containing values separated by ";". i would like to have those seperate values to be indexed somehow (preferaby using a macro) so that i could use appropriate one for the further calculations. please can anyone give me assistance on this one? respect hu ps i have Excel 2003 |
|
|
|
|
|
#2 | |
|
Join Date: Feb 2002
Posts: 7,599
|
Quote:
|
|
|
|
|
|
|
#3 |
|
Join Date: Apr 2003
Location: Latvia
Posts: 56
|
well... no.
because it will not yield the results required. i need to split the value into respective number of parts (using ";" as delimiter) so that i could call up the needed value according to further calculation concept. let's suppose A1 contains following value "a;b;c;d;e" (except for ""). i would like to be able to reference to each one of the elements for use in Select Case statement. is this clear? respect hu |
|
|
|
|
|
#4 | |
|
Join Date: Feb 2002
Posts: 7,599
|
Quote:
|
|
|
|
|
|
|
#5 |
|
Join Date: Apr 2003
Location: Latvia
Posts: 56
|
well...
thank you for trying! respect Hu |
|
|
|
|
|
#6 |
|
Join Date: Dec 2002
Location: ashbourne, derbyshire, uk
Posts: 86
|
Hi
This is a UDF I use a lot...It may help you here 'Extract "field" from string ' ' ' field = fsplit(str,fs,jf) ' str = string containg field(s) ' fs= field separator string (normally a single char) ' jf = index of field required ' 0 = return number of fields in string ' +n = return nth field from start of string (ie. use +1 to get first field) ' -n = return nth field from the end of the string (ie. use -1 to get last field) ' ' field = Returned field (or field count) ' ' Notes : 1) returns a null string if you ask for a field that doesn't exist ' 2) if str is non-null but does not contain fs then there is precisely one field in str (even if fs is null) ' 3) if str is null then there are no fields in the string (unless fs =null too, in which case there is precisely one, namely null) ' ' ' #### Future improvements ' A) for fs = " " , treat multiple blanks as a single field separator ' (this is left as an exercise for the reader, cos I cannot be bothered right now) ' Function fsplit(str, fs, jf) Dim f As Variant f = Split(str, fs, -1) nf = UBound(f) + 1 If jf = 0 Then fsplit = nf ElseIf jf > 0 Then If jf > nf Then fsplit = "" Else fsplit = f(jf - 1) End If Else If jf < -nf Then fsplit = "" Else fsplit = f(nf + jf) End If End If End Function Any use? Rob |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|