Append a backslash "\" to the end of a text string

jase71ds

Board Regular
Joined
Oct 23, 2006
Messages
135
Office Version
  1. 365
Platform
  1. Windows
In cell A1, I have a file path (simple text string) and I need to append (via macro, not via formula) a backslash. The text file will vary in length.

Example 1
This:.......... "C:\rouk1\stators"
Needs to be: "C:\rouk1\stators\"

Example 2
This:........... "D:\thrstr\engr\nozzle\flak\trim"
Needs to be: "D:\thrstr\engr\nozzle\flak\trim\"

Should be simple, but I'm lost. Would appreciate any help.
Thanks.
Jase.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
7,493
Office Version
  1. 365
Platform
  1. Windows
Code:
Dim myPath as string
myPath = [COLOR=#333333]"D:\thrstr\engr\nozzle\flak\trim"
myPath = [/COLOR][COLOR=#333333]myPath & "\"[/COLOR]
 
Upvote 0

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
15,060
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Assuming you are just amending the cell and you don't have the quote marks in the cell.
Code:
Range("A1") = Range("A1") & "\"
 
Upvote 0

Teeroy

Well-known Member
Joined
Nov 9, 2012
Messages
2,244
Office Version
  1. 365
Platform
  1. Windows
I suggest you also check for an existing trailing "\" before adding one. e.g.

Code:
If right(Range("A2").value,1)<>"\" then
    Range("A2").value = Range("A2").value & "\"
End if

BTW it sounds like you're a bit of a turbojet nut :)
 
Upvote 0

jase71ds

Board Regular
Joined
Oct 23, 2006
Messages
135
Office Version
  1. 365
Platform
  1. Windows
Thanks guys, all of you, very much!
And great advice, Teeroy, about first checking to see if there already is a backslash.
 
Upvote 0

Forum statistics

Threads
1,191,707
Messages
5,988,223
Members
440,139
Latest member
ngaicuong2017

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top