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

jase71ds

Board Regular
Joined
Oct 23, 2006
Messages
137
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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Code:
Dim myPath as string
myPath = [COLOR=#333333]"D:\thrstr\engr\nozzle\flak\trim"
myPath = [/COLOR][COLOR=#333333]myPath & "\"[/COLOR]
 
Upvote 0
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
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
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,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

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
Back
Top