Remove Last x Character(s) in Selected Cells

P

PCLIVE

One way using the active cell:
ActiveCell.Value = Left(ActiveCell.Value, Len(ActiveCell.Value) - 2)

If you want a specific cell reference:
Range("A1").Value = Left(Range("A1").Value, Len(Range("A1").Value) - 2)

HTH,
Paul
 
J

JE McGimpsey

One way:

Public Sub RemoveLastXCharacters()
Const cnX As Long = 2
Dim rCell As Range
Dim nLen As Long
For Each rCell In Selection
With rCell
nLen = Len(.Text) - cnX
If nLen <= 0 Then
.ClearContents
Else
.Value = Left(.Text, nLen)
End If
End With
Next rCell
End Sub

Note: If the values are numeric, the last two digits will be "removed",
but the number of displayed digits will still be set by the number
format, so

1.2345

will display as

1.2300

if the format displays 4 digits after then decimal place.
 
B

Barb Reinhardt

Here's an equation to do it in helper column

=left(A1,len(A1)-2)

Do you need it in a macro?
 
D

David Biddulph

LEFT and LEN are both standard Excel functions. Their operation and syntax,
and the operation and syntax of every Excel function except DATEDIF, is
shown in Excel help. One of many ways of getting to Excel help is to hit
the F1 button. I would heartily recommend it as a first port of call.
 

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

Top