ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checking a String's last character (https://www.excelbanter.com/excel-programming/369130-checking-strings-last-character.html)

Ren

Checking a String's last character
 
I want to get a folder path from a a cell and have a check function where the
function would check if the string's last character is "\"

So that if the String is "C:\folderpath" the string would return
"C:\folderpath\" and leave it as is if the String is "C:\folderpath\"

What VBA function would allow me to do so?

Graham Whitehead

Checking a String's last character
 
You need to use the Right function, here is a short example

Dim strTest As String
Dim strExample As String

strTest = Range("E1").Value
strExample = Right(strTest, 1)

If strExample < "\" Then
strTest = strTest & "\"
End If

"Ren" wrote in message
...
I want to get a folder path from a a cell and have a check function where
the
function would check if the string's last character is "\"

So that if the String is "C:\folderpath" the string would return
"C:\folderpath\" and leave it as is if the String is "C:\folderpath\"

What VBA function would allow me to do so?




Dave Peterson

Checking a String's last character
 
dim myPath as string
mypath = "c:\folderpath"
if right(mypath,1) < "\" then
mypath = mypath & "\"
end if



Ren wrote:

I want to get a folder path from a a cell and have a check function where the
function would check if the string's last character is "\"

So that if the String is "C:\folderpath" the string would return
"C:\folderpath\" and leave it as is if the String is "C:\folderpath\"

What VBA function would allow me to do so?


--

Dave Peterson

Ron Rosenfeld

Checking a String's last character
 
On Wed, 2 Aug 2006 07:36:02 -0700, Ren wrote:

I want to get a folder path from a a cell and have a check function where the
function would check if the string's last character is "\"

So that if the String is "C:\folderpath" the string would return
"C:\folderpath\" and leave it as is if the String is "C:\folderpath\"

What VBA function would allow me to do so?


Just another method:

path = "C:\folderpath"
Replace(path & "\", "\\", "\")



--ron

Dave Peterson

Checking a String's last character
 
I'd watch out for UND paths, though:

Dim myPath As String
myPath = "\\share\folderpath"
myPath = Replace(myPath & "\", "\\", "\")



Ron Rosenfeld wrote:

On Wed, 2 Aug 2006 07:36:02 -0700, Ren wrote:

I want to get a folder path from a a cell and have a check function where the
function would check if the string's last character is "\"

So that if the String is "C:\folderpath" the string would return
"C:\folderpath\" and leave it as is if the String is "C:\folderpath\"

What VBA function would allow me to do so?


Just another method:

path = "C:\folderpath"
Replace(path & "\", "\\", "\")

--ron


--

Dave Peterson

Dave Peterson

Checking a String's last character
 
er, UNC paths....

Darn fingers!

Dave Peterson wrote:

I'd watch out for UND paths, though:

Dim myPath As String
myPath = "\\share\folderpath"
myPath = Replace(myPath & "\", "\\", "\")

Ron Rosenfeld wrote:

On Wed, 2 Aug 2006 07:36:02 -0700, Ren wrote:

I want to get a folder path from a a cell and have a check function where the
function would check if the string's last character is "\"

So that if the String is "C:\folderpath" the string would return
"C:\folderpath\" and leave it as is if the String is "C:\folderpath\"

What VBA function would allow me to do so?


Just another method:

path = "C:\folderpath"
Replace(path & "\", "\\", "\")

--ron


--

Dave Peterson


--

Dave Peterson

Ron Rosenfeld

Checking a String's last character
 
On Wed, 02 Aug 2006 10:27:54 -0500, Dave Peterson
wrote:

er, UNC paths....

Darn fingers!

Dave Peterson wrote:

I'd watch out for UND paths, though:

Dim myPath As String
myPath = "\\share\folderpath"
myPath = Replace(myPath & "\", "\\", "\")


Excellent point! and one which I overlooked.


--ron


All times are GMT +1. The time now is 01:13 PM.

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