Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Ross
 
Posts: n/a
Default how to extract a filename?

a cell contains:

C:\Program Files\Amersham Biosciences\ImageMaster 2D Platinum
Trial\Gels\94-0005.mel


How to obtain 94-0005 in this case? certainly, the path can also be d: and
the filename is of any combinations of characters in general.

i find "FIND, MID, MATCH, RIGHT, ..." doesn't do a good job, thx!!


  #2   Report Post  
Ross
 
Posts: n/a
Default

C:\Program Files\Amersham Biosciences\ImageMaster 2D Platinum
Trial\Gels\94-0005.mel


How to obtain 94-0005 in this case? certainly, the path can also be d: and
the filename is of any combinations of characters in general.

i find "FIND, MID, MATCH, RIGHT, ..." doesn't do a good job, and
"data-TexttoColumn" can solve but it requires manual physical separation
and what i what is just to extract the content, thx!!



  #3   Report Post  
cola
 
Posts: n/a
Default

=LEFT(MID(CELL("filename"),FIND("[",CELL("filename"))+1,FIND("]",CELL("filen
ame"))-FIND("[",CELL("filename"))-1),LEN(MID(CELL("filename"),FIND("[",CELL(
"filename"))+1,FIND("]",CELL("filename"))-FIND("[",CELL("filename"))-1))-4)


  #4   Report Post  
Ross
 
Posts: n/a
Default


"cola" wrote in message
...
=LEFT(MID(CELL("filename"),FIND("[",CELL("filename"))+1,FIND("]",CELL("filen
ame"))-FIND("[",CELL("filename"))-1),LEN(MID(CELL("filename"),FIND("[",CELL(
"filename"))+1,FIND("]",CELL("filename"))-FIND("[",CELL("filename"))-1))-4)



what do you mean by "filename"? i cannot specify it because i suppose the
formula is to be generic for all different filenames that may be encountered
by different users. thx again.


  #5   Report Post  
Biff
 
Posts: n/a
Default

Hi!

With the path/file name in A1:

=MID(A1,FIND("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN
(SUBSTITUTE(A1,"\",""))))+1,FIND(".",A1)-1-FIND
("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN(SUBSTITUTE
(A1,"\","")))))

Biff

-----Original Message-----
C:\Program Files\Amersham Biosciences\ImageMaster 2D

Platinum
Trial\Gels\94-0005.mel


How to obtain 94-0005 in this case? certainly, the path

can also be d: and
the filename is of any combinations of characters in

general.

i find "FIND, MID, MATCH, RIGHT, ..." doesn't do a good

job, and
"data-TexttoColumn" can solve but it requires manual

physical separation
and what i what is just to extract the content, thx!!



.



  #6   Report Post  
Ross
 
Posts: n/a
Default


"Biff" wrote in message
...
Hi!

With the path/file name in A1:

=MID(A1,FIND("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN
(SUBSTITUTE(A1,"\",""))))+1,FIND(".",A1)-1-FIND
("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN(SUBSTITUTE
(A1,"\","")))))

Biff

-----Original Message-----
C:\Program Files\Amersham Biosciences\ImageMaster 2D

Platinum
Trial\Gels\94-0005.mel


How to obtain 94-0005 in this case? certainly, the path

can also be d: and
the filename is of any combinations of characters in

general.

i find "FIND, MID, MATCH, RIGHT, ..." doesn't do a good

job, and
"data-TexttoColumn" can solve but it requires manual

physical separation
and what i what is just to extract the content, thx!!


oh thx Biff :) but what's the meaning of '~'? and could you very briefly
describe what the expression you write mean? thx again for your kind
assistance.

--Ross


  #7   Report Post  
Biff
 
Posts: n/a
Default

Hi!

...what's the meaning of '~'?


That's just an arbitrary character.

Here's how it works:

In your example, you want to extract a portion of the file
name. We know that the file name starts after the last
instance of "\", so we have to find that last instance.
Since we know the last instance is the one we're looking
for we simply count the number of "\" in the string:

LEN(A1)-LEN(SUBSTITUTE(A1,"\","")) = 5

Now we can look for the 5th instance of "\" and when we
find it we want to "mark that spot". So we use the
Substitute function to replace the last instance of "\"
with a unique character that will more than likely not
appear in the string. So I chose to use the tilde
character,"~". So we add the Substitute function to the
formula:

SUBSTITUTE(A1,"\","~",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))

Now, this is what your string would look like after
processing that portion of the formula:

C:\Program Files\Amersham Biosciences\ImageMaster 2D
Platinum Trial\Gels~94-0005.mel

Now we tell the formula to look for the starting point of
the substring that we want to extract. That starting point
is the character after the "~":

=MID(A1,FIND("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN
(SUBSTITUTE(A1,"\",""))))+1 = 74

Now we have to tell the formula how many characters to
return starting from the character after the "~". We want
to extract all the characters between the "~" and the ".".
WE know where the "~" is so all we need to do is find
the "." and subtract to get the number of characters we
want the formula to return. So we find the "." and
subtract 1 because we want the last character before
the ".":

FIND(".",A1)-1 = 80


Then subtract the location of the "~":

-FIND("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN(SUBSTITUTE
(A1,"\","")))) = 73

So, 80 - 73 = 7

Put it all together:

Return the 7 character string starting from the 74th
character = 94-0005

Long winded but that's a pretty thorough explanation!

Biff

-----Original Message-----

"Biff" wrote in message
...
Hi!

With the path/file name in A1:

=MID(A1,FIND("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN
(SUBSTITUTE(A1,"\",""))))+1,FIND(".",A1)-1-FIND
("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN(SUBSTITUTE
(A1,"\","")))))

Biff

-----Original Message-----
C:\Program Files\Amersham Biosciences\ImageMaster 2D

Platinum
Trial\Gels\94-0005.mel


How to obtain 94-0005 in this case? certainly, the path

can also be d: and
the filename is of any combinations of characters in

general.

i find "FIND, MID, MATCH, RIGHT, ..." doesn't do a good

job, and
"data-TexttoColumn" can solve but it requires manual

physical separation
and what i what is just to extract the content, thx!!


oh thx Biff :) but what's the meaning of '~'? and could

you very briefly
describe what the expression you write mean? thx again

for your kind
assistance.

--Ross


.

  #8   Report Post  
Biff
 
Posts: n/a
Default

Hi!

Cola's formula will return the file name of the active
(open) workbook (file) provided that it's been saved and
named already.

Biff

-----Original Message-----

"cola" wrote in message
...
=LEFT(MID(CELL("filename"),FIND("[",CELL("filename"))

+1,FIND("]",CELL("filen
ame"))-FIND("[",CELL("filename"))-1),LEN(MID(CELL

("filename"),FIND("[",CELL(
"filename"))+1,FIND("]",CELL("filename"))-FIND("[",CELL

("filename"))-1))-4)



what do you mean by "filename"? i cannot specify it

because i suppose the
formula is to be generic for all different filenames that

may be encountered
by different users. thx again.


.

  #9   Report Post  
Ross
 
Posts: n/a
Default

Brilliant, clapping.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 Question: Coloumn width, Filename nopfusch Excel Worksheet Functions 2 March 15th 05 07:43 PM
extract numbers, convert to date gkaspen Excel Discussion (Misc queries) 7 March 2nd 05 02:31 AM
Extract specific data into its own workbook via macro? Adrian B Excel Discussion (Misc queries) 2 February 24th 05 06:09 AM
How do I join a filename and a cellreference, by just filling in . René Excel Worksheet Functions 1 February 23rd 05 02:24 PM
Insert value of a cell as a filename Ralph Howarth Excel Worksheet Functions 0 January 18th 05 12:03 AM


All times are GMT +1. The time now is 11:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"