ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Truncate text (https://www.excelbanter.com/excel-programming/294326-truncate-text.html)

james

Truncate text
 
Hi Gan
How can I truncate text to the right of and including / in a cell. Woul dlike to do it through cod
Thanks!

Bob Phillips[_6_]

Truncate text
 
aCtivecell.value = left(activecell.value,instr(1,activecell.value,"/")-1)


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"JAmes" wrote in message
...
Hi Gang
How can I truncate text to the right of and including / in a cell. Woul

dlike to do it through code
Thanks!




Steve Garman

Truncate text
 
If you mean you want to retain everything to the left of the "/" try:

Sub test()
Dim pos&, rng As Range
Set rng = Range("A1")
pos& = InStr(1, rng.Value, "/")
If pos& Then rng.Value = Left(rng.Value, pos& - 1)
End Sub

JAmes wrote:
Hi Gang
How can I truncate text to the right of and including / in a cell. Woul dlike to do it through code
Thanks!



Rob van Gelder[_4_]

Truncate text
 
I think InStrRev is XL2000

Sub test()
Dim str As String

str = "abcde/fghij/klmno/pqrst"
str = Mid(str, InStrRev(str, "/"))
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"JAmes" wrote in message
...
Hi Gang
How can I truncate text to the right of and including / in a cell. Woul

dlike to do it through code
Thanks!




james

Truncate text
 
Can this be applied to a range or do I have to loop through the range
Thanks for the response!

Bob Phillips[_6_]

Truncate text
 
No, you can set a value to a range, but for this you will need to loop
through each cell.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"James" wrote in message
...
Can this be applied to a range or do I have to loop through the range?
Thanks for the response!




Frank Kabel

Truncate text
 
Hi
you have to loop through the range

--
Regards
Frank Kabel
Frankfurt, Germany

"James" schrieb im Newsbeitrag
...
Can this be applied to a range or do I have to loop through the

range?
Thanks for the response!




All times are GMT +1. The time now is 10:34 AM.

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