Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Extract Name from File Path

Hi all, in cell A1 i have file path as below

C:\Documents and Settings\My Documents\Tests\Test1\Simon Brown.txt

and i got macro on a button (see below)

Sub Button1_Click()
cv = Range("a1").Value
Range("a3").Value = Right(cv, Len(cv) - InStrRev(cv, "\"))
End Sub

I get result "Simon Brown.txt" in cell A3 but i just need result
"Simon Brown". So please can anyone help that what changes i should
do in my macro above which should get rid of any thing after dot
like .txt and just give the person name like "Simon Brown"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Extract Name from File Path

Hi

This should do it:

cv = Range("a1").Value
cv = Right(cv, Len(cv) - InStrRev(cv, "\"))
Range("A3") = Left(cv, InStr(cv, ".") - 1)

Regards,
Per

"K" skrev i meddelelsen
...
Hi all, in cell A1 i have file path as below

C:\Documents and Settings\My Documents\Tests\Test1\Simon Brown.txt

and i got macro on a button (see below)

Sub Button1_Click()
cv = Range("a1").Value
Range("a3").Value = Right(cv, Len(cv) - InStrRev(cv, "\"))
End Sub

I get result "Simon Brown.txt" in cell A3 but i just need result
"Simon Brown". So please can anyone help that what changes i should
do in my macro above which should get rid of any thing after dot
like .txt and just give the person name like "Simon Brown"


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Extract Name from File Path

That code will work as long as the filename does, in fact, have an
extension. Here is some alternate code which will work whether the filename
has an extension or not...

cv = Range("A1").Value
Range("A3").Value = Split(Split(cv, "\")(UBound(Split(cv, "\"))), ".")(0)

--
Rick (MVP - Excel)


"Per Jessen" wrote in message
...
Hi

This should do it:

cv = Range("a1").Value
cv = Right(cv, Len(cv) - InStrRev(cv, "\"))
Range("A3") = Left(cv, InStr(cv, ".") - 1)

Regards,
Per

"K" skrev i meddelelsen
...
Hi all, in cell A1 i have file path as below

C:\Documents and Settings\My Documents\Tests\Test1\Simon Brown.txt

and i got macro on a button (see below)

Sub Button1_Click()
cv = Range("a1").Value
Range("a3").Value = Right(cv, Len(cv) - InStrRev(cv, "\"))
End Sub

I get result "Simon Brown.txt" in cell A3 but i just need result
"Simon Brown". So please can anyone help that what changes i should
do in my macro above which should get rid of any thing after dot
like .txt and just give the person name like "Simon Brown"



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 to extract only file name from folder path string in Excel? JayKay Excel Worksheet Functions 1 March 20th 09 04:57 PM
extract path from FullName Judy Ward Excel Programming 4 February 3rd 09 11:34 PM
How to extract data from File Path DK Excel Programming 16 June 14th 07 01:03 AM
Formula too long - new file path is shorter than old file path - Excel 2003 Greg J Excel Worksheet Functions 1 November 22nd 06 05:16 PM
Extract Path From String Andibevan[_2_] Excel Programming 2 June 15th 05 07:04 PM


All times are GMT +1. The time now is 09:41 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"