VB Macro

G

Guest

It used to be that you could record a macro and it would replicate the
actions you did while recording i.e. open cell, backspace four times, return
- and the result would be that you would eliminate the last four charecters
in each of the cells where you ran the macro. This does not seem to be the
case any longer since Excel now uses VB.
I would appreciate advice on the entries to make in VB to accomplish
eliminating the last four charecters of a cells contents.
Many Thanks!
 
P

PCLIVE

One way,

Sub RemoveLastFour()

n = ActiveCell.Value
r = Len(ActiveCell) - 4
ActiveCell = Left(n, r)

End Sub

Regards,
Paul
 
K

Ken Puls

Or, for a selected range:

Sub RemoveLastFourFromAll()
Dim cl as Range
'Stop screen flashing
Application.Screenupdating = False

'Remove last 4 characters
For Each cl in Selection
cl.value = Left(cl.value,Len(cl.value)-4))
Next cl

Application.Screenupdating = True
End Sub

This will work on all cells within the selected area
 

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