Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ren Ren is offline
external usenet poster
 
Posts: 67
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default 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
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
Spell Checking with checking cell notes jfitzpat Excel Discussion (Misc queries) 0 August 8th 07 10:26 PM
importing undelimited text file data, character-by-character The Mos$ Excel Programming 4 December 26th 05 11:01 AM
Checking to see whether a string contains a certain character ajitpalsingh200[_21_] Excel Programming 1 November 26th 04 09:36 AM
Repost: How to calc string's printable width? count Excel Programming 1 December 8th 03 06:44 PM
Checking the last character is in a list [email protected] Excel Programming 2 August 18th 03 11:37 AM


All times are GMT +1. The time now is 03:51 AM.

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"