Apr 28, 2001 #1 cjhepburn Technical User Mar 9, 2001 8 US I've been puzzling over this for a while. I have a formula "=cell("filename"" that gives me "c:\xxx\yyy\ttt\excel.xls" How do I get the cell block to return "ttt"?
I've been puzzling over this for a while. I have a formula "=cell("filename"" that gives me "c:\xxx\yyy\ttt\excel.xls" How do I get the cell block to return "ttt"?
Apr 28, 2001 #2 JVFriederick IS-IT--Management Mar 19, 2001 517 US If you need the complete directory, without filename : =MID(CELL("filename",A1),1,FIND("[",CELL("filename",A1))-2) If you want to trim the drive letter out : =MID(CELL("filename",A1),3,FIND("[",CELL("filename",A1))-4) If you want JUST the last directory name : Tried, but I don't know how to do that ! Sorry. :-( Upvote 0 Downvote
If you need the complete directory, without filename : =MID(CELL("filename",A1),1,FIND("[",CELL("filename",A1))-2) If you want to trim the drive letter out : =MID(CELL("filename",A1),3,FIND("[",CELL("filename",A1))-4) If you want JUST the last directory name : Tried, but I don't know how to do that ! Sorry. :-(
Apr 30, 2001 #3 Store300 Technical User Apr 5, 2001 63 GB You can use the FIND function to discover where the "\" characters are and then use the MID, LEFT or RIGHT functions to trim the string Upvote 0 Downvote
You can use the FIND function to discover where the "\" characters are and then use the MID, LEFT or RIGHT functions to trim the string
Apr 30, 2001 2 #4 DarkSun Programmer Mar 8, 2001 232 GB Try This: Insert this function into a Module in the Workbook. Public Function GetLastDirectory(Pathname As String) Dim LookPos As Integer Dim PrevPos As Integer LookPos = 0 Do While InStr(1, Pathname, "\" <> 0 If InStr(LookPos + 1, Pathname, "\" = 0 Then Pathname = Mid(Pathname, PrevPos + 1, (LookPos - PrevPos - 1)) Exit Do End If PrevPos = LookPos LookPos = InStr(LookPos + 1, Pathname, "\" Loop GetLastDirectory = Pathname End Function Then you can enter something like this into a cell =getlastdirectory(cell("filename") Let me know if you have any problems. Upvote 0 Downvote
Try This: Insert this function into a Module in the Workbook. Public Function GetLastDirectory(Pathname As String) Dim LookPos As Integer Dim PrevPos As Integer LookPos = 0 Do While InStr(1, Pathname, "\" <> 0 If InStr(LookPos + 1, Pathname, "\" = 0 Then Pathname = Mid(Pathname, PrevPos + 1, (LookPos - PrevPos - 1)) Exit Do End If PrevPos = LookPos LookPos = InStr(LookPos + 1, Pathname, "\" Loop GetLastDirectory = Pathname End Function Then you can enter something like this into a cell =getlastdirectory(cell("filename") Let me know if you have any problems.
Apr 30, 2001 #5 JVFriederick IS-IT--Management Mar 19, 2001 517 US Very cool. Did we loose the original author? Upvote 0 Downvote
Apr 30, 2001 Thread starter #6 cjhepburn Technical User Mar 9, 2001 8 US Thanks, works beautifully. Upvote 0 Downvote