Truncate text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Gan
How can I truncate text to the right of and including / in a cell. Woul dlike to do it through cod
Thanks!
 
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)
 
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
 
I think InStrRev is XL2000

Sub test()
Dim str As String

str = "abcde/fghij/klmno/pqrst"
str = Mid(str, InStrRev(str, "/"))
End Sub
 
Can this be applied to a range or do I have to loop through the range
Thanks for the response!
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top