ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trim "\" Value (https://www.excelbanter.com/excel-programming/296778-trim-%5C-value.html)

Todd huttenstine

Trim "\" Value
 
Hey guys I have the following value of a variable:

Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas

I would like to trim that value to where it only gives me
the value "test.bas"

How do I do this?


Thanx
Todd Huttenstine

Juan Pablo González

Trim "\" Value
 
Try something like

Function GetName(FullPath As String) As String
Dim FileName As Variant
FileName = Split(FullPath, Application.PathSeparator)
FileName = FileName(UBound(FileName))
GetName = FileName
End Function

--
Regards,

Juan Pablo González

"Todd Huttenstine" wrote in message
...
Hey guys I have the following value of a variable:

Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas

I would like to trim that value to where it only gives me
the value "test.bas"

How do I do this?


Thanx
Todd Huttenstine




Melanie Breden

Trim "\" Value
 
Hi Todd,

Todd Huttenstine schrieb:
Hey guys I have the following value of a variable:

Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas

I would like to trim that value to where it only gives me
the value "test.bas"

How do I do this?


since Excel2000 you can use the Split Function:

Dim strText As String
Dim varSplit As Variant

strText = "Q:\CS Management Reports\Reports Setup\AdministratorFiles\Exported Modules\test.bas"
varSplit = VBA.Split(strText, "\")
strText = varSplit(UBound(varSplit))

--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)


Hawk

Trim "\" Value
 
Public Function fileNameOnly(fPth As String) As String
Dim i As Integer, length As Integer, Temp As String

length = Len(fPth)
Temp = ""
For i = length To 1 Step -1
If Mid(fPth, i, 1) = Application.PathSeparator Then
fileNameOnly = Temp
Exit Function
End If
Temp = Mid(fPth, i, 1) & Temp
Next i
fileNameOnly = fPth
End Function
-----Original Message-----
Hey guys I have the following value of a variable:

Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas

I would like to trim that value to where it only gives me
the value "test.bas"

How do I do this?


Thanx
Todd Huttenstine
.


pikus

Trim "\" Value
 
strVar = "Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas"
strLen = Len(strVar)
slashLoc = InStrRev(strVar, "\")
fileNameLen = strLen - slashLoc
fileName = Right(strVar, fileNameLen)

This works in theory, but I haven't tested it so let me know if it doe
not work. - Piku

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

Trim "\" Value
 
The code samples that used Split (or VBA.Split) will work for xl2k or higher.
The other code is should work in all versions. (I didn't test, though.)

Split was added in xl2k.



Todd Huttenstine wrote:

Hey guys I have the following value of a variable:

Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas

I would like to trim that value to where it only gives me
the value "test.bas"

How do I do this?

Thanx
Todd Huttenstine


--

Dave Peterson


Steve Garman

Trim "\" Value
 
Dave Peterson wrote:
The code samples that used Split (or VBA.Split) will work for xl2k or higher.
The other code is should work in all versions. (I didn't test, though.)

Split was added in xl2k.


And I think the same restriction applies to the InStrRev sample


Tom Ogilvy

Trim "\" Value
 
absolutely.

--
Regards,
Tom Ogilvy

"Steve Garman" wrote in message
...
Dave Peterson wrote:
The code samples that used Split (or VBA.Split) will work for xl2k or

higher.
The other code is should work in all versions. (I didn't test, though.)

Split was added in xl2k.


And I think the same restriction applies to the InStrRev sample





All times are GMT +1. The time now is 10:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com