Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
xhm xhm is offline
external usenet poster
 
Posts: 3
Default How to find multiple same char in a string in Excel?

Hello:

I am trying to locate the last subdirectory name from a full path. For
example, I have a full path like:

"c:\temp\temp1\temp2"

I would like to find the temp2 which is the last subdirectory.

I am thinking to use find() to find the last "\", and then use left(),
right() or mid() to obtain it. The problem is, when I tried to use
find() function, it only returns the first position of the "\" in the
full path string. How can I get the last "\" position in the string?

p.s., I had searched the Internet, but all the examples I found were
just had one occurance of the char to be found, while in my case, I
have multiple same chars ("\") in the string.

Thanks for any help in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default How to find multiple same char in a string in Excel?

On Tue, 9 Feb 2010 09:02:31 -0800 (PST), xhm wrote:

Hello:

I am trying to locate the last subdirectory name from a full path. For
example, I have a full path like:

"c:\temp\temp1\temp2"

I would like to find the temp2 which is the last subdirectory.

I am thinking to use find() to find the last "\", and then use left(),
right() or mid() to obtain it. The problem is, when I tried to use
find() function, it only returns the first position of the "\" in the
full path string. How can I get the last "\" position in the string?

p.s., I had searched the Internet, but all the examples I found were
just had one occurance of the char to be found, while in my case, I
have multiple same chars ("\") in the string.

Thanks for any help in advance.


Try:

=TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),99))

which will return that last "\" separated substring from your string.
--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default How to find multiple same char in a string in Excel?

Take a look at INSTRREV

It'll find the last occurence
Repeat the task to find the second last and then extract the text from the
two points
Something like this :

cText = "c:\First Folder\Second Folder\File.xls"
nLast = InStrRev(cText, "\")
n2Last = InStrRev(cText, "\", nLast - 1)

cFolder = Mid(cText, n2Last + 1, nLast - n2Last - 1)
--
If the post is helpful, please consider donating something to an animal
charity on my behalf.


"xhm" wrote:

Hello:

I am trying to locate the last subdirectory name from a full path. For
example, I have a full path like:

"c:\temp\temp1\temp2"

I would like to find the temp2 which is the last subdirectory.

I am thinking to use find() to find the last "\", and then use left(),
right() or mid() to obtain it. The problem is, when I tried to use
find() function, it only returns the first position of the "\" in the
full path string. How can I get the last "\" position in the string?

p.s., I had searched the Internet, but all the examples I found were
just had one occurance of the char to be found, while in my case, I
have multiple same chars ("\") in the string.

Thanks for any help in advance.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default How to find multiple same char in a string in Excel?

This will work for you. Hope this helps! If so, let me know, click "YES"
below.

Sub GetFileName()

Dim myFullPath As String
Dim myDirs As Variant
Dim myFileName As String

myFullPath = "C:\temp\temp1\temp2"

myDirs = Split(myFullPath, "\")

myFileName = myDirs(UBound(myDirs))

End Sub
--
Cheers,
Ryan


"xhm" wrote:

Hello:

I am trying to locate the last subdirectory name from a full path. For
example, I have a full path like:

"c:\temp\temp1\temp2"

I would like to find the temp2 which is the last subdirectory.

I am thinking to use find() to find the last "\", and then use left(),
right() or mid() to obtain it. The problem is, when I tried to use
find() function, it only returns the first position of the "\" in the
full path string. How can I get the last "\" position in the string?

p.s., I had searched the Internet, but all the examples I found were
just had one occurance of the char to be found, while in my case, I
have multiple same chars ("\") in the string.

Thanks for any help in advance.

.

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
How can I find a value from one cell in a char string in another? tiredazdaddy Excel Worksheet Functions 2 November 20th 08 05:40 PM
FIND 1 char in cell of any 3 char =True Nastech Excel Discussion (Misc queries) 5 April 26th 08 02:17 PM
Find char in string and mark Fred[_21_] Excel Programming 3 July 24th 07 06:18 PM
How to verify the first char of the string in excel? Eric Excel Discussion (Misc queries) 0 November 30th 06 03:57 AM
How to verify the first char of the string in excel? Teethless mama Excel Discussion (Misc queries) 0 November 30th 06 03:51 AM


All times are GMT +1. The time now is 09:48 PM.

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

About Us

"It's about Microsoft Excel"