Truncate

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

Guest

Hell
Im trying to pices together code from here that will truncate the text to the left of and including "/"
This is what I have so far but it isnt working.

Sub Truncat

Dim rng As Rang
Dim c As Rang
Set rng = Selectio
For Each c In rn
c.Value = Left(ActiveCell.Value, InStr(1, ActiveCell.Value, "/") - 1
Nex
End Su

All help is greatly appreciated
Steven
 
Hi Steve
try
Sub Truncate

Dim rng As Range
Dim c As Range
Set rng = Selection
For Each c In rng
c.Value = Left(c.Value, InStr(1, c.Value, "/") - 1)
Next
End Sub
 
Thanks Fran
I had tried that and I am getting "Invalid Procedure Call" on

c.Value = Left(c.Value, InStr(1, c.Value, "/") - 1

Thanks again
 
Thanks Fran
I had tried that and I am getting "Invalid Procedure Call" on

c.Value = Left(c.Value, InStr(1, c.Value, "/") - 1

Thanks again
 
You might want to check that the cell actually contains a "/" or yo
might get unpleasant results/error.

Sub Truncate

Dim rng As Range
Dim c As Range
Set rng = Selection
For Each c In rng
if instr(1,c.value,"/") <> 0 then
c.Value = Left(c.Value, InStr(1, c.Value, "/") - 1)
End if
Next
End Sub

if the cells contain dates, you might want to change Value to Text
 
That is because you cell doesn't contain a "/", at least the value property
doesn't

try putting in a text

if instr(1,c.value,"/") <> 0 then
c.Value = Left(c.Value, InStr(1, c.Value, "/") - 1)
End if
 
Thanks To
That worked as posted---now I realize I need to save to right of "/" so what would the modification be....
Thanks for all of your help
Steven
 
Thanks To
That worked as posted---now I realize I need to save to right of "/" so what would the modification be....
Thanks for all of your help
Steven
 
Sub Truncate

Dim rng As Range
Dim c As Range
Dim ln as Long
Set rng = Selection
For Each c In rng
if instr(1,c.value,"/") <> 0 then
c.Value = Mid(c.Value, InStr(1, c.Value, "/") + 1 ,255)
' '''or
' ln = len(c.value) - instr(1,c.Value,"/")
' c.Value = Right(c.Value,ln)
End if
Next
End Sub

--
Regards,
Tom Ogilvy

Steven said:
Thanks Tom
That worked as posted---now I realize I need to save to right of "/" so
what would the modification be.....
 
I cant get my left and right straight. I need to save to the left of the "/" EG. I am stupid/YES/NO...tuncated gives ..
I am stupid

Thanks!
 
Back
Top