Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Spell Checking with checking cell notes | Excel Discussion (Misc queries) | |||
importing undelimited text file data, character-by-character | Excel Programming | |||
Checking to see whether a string contains a certain character | Excel Programming | |||
Repost: How to calc string's printable width? | Excel Programming | |||
Checking the last character is in a list | Excel Programming |