View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Remove Last x Character(s) in Selected Cells

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.

In article ,
rojobrown wrote:

How do you remove the last two digits in a cell using a macro?