Delete first character in ActiveCell

A

Andy

What would the code be to delete the first character in the Active
Cell? So abc123 would become bc123? It's easy to add a character to
the beginning of the string, but I can't figure out how to delete it.

TIA,

Andy
 
J

jseven

Sub tester()
ActiveCell.Value = Right(ActiveCell.Value, Len(ActiveCell.Value) -
1)

End Sub


Others may have better ways, but this one seems to work great for me.
Jamie
 
D

David

This will do a single value. See "Excel Macro Help", not far below for loop
to check mutiple values in a column.

Sub ChangeValue1()
'Can not recover the original value, this overwrites the value, need to loop
to go thru
' a lot of values
OriginalValue = ActiveCell.Value
LengthOrig = Len(ActiveCell.Value)
NewValue = Right(OriginalValue, LengthOrig - 1)
ActiveCell.Value = NewValue
End Sub
Thanks,
David
 
A

Andy

ActiveCell.Value = Right(ActiveCell.Value, Len(ActiveCell.Value) -1)

That did it.

Thanks everyone!

Andy
 
A

AA2e72E

The solution :

ActiveCell.Value = Right(ActiveCell.Value, Len(ActiveCell.Value) -1)

will fail with error 5 whenever the active cell is empty.

You might want to try this instead:

ActiveCell.Value = Mid(ActiveCell.Value,2)
 
D

Dana DeLouis

Just a note. Vba's Mid function works a little differently that the
worksheet version.

ActiveCell = Mid$(ActiveCell, 2)
 
A

Andy

Just a note. Vba's Mid function works a little differently that the
worksheet version.

ActiveCell = Mid$(ActiveCell, 2)


I have a hard time finding what I'm looking for in VBA help. Now I see
that Mid$ doesn't require that the length be specified. Very handy.


Andy
 

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