Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
try this code after highllightig the concerned cell
Public Sub test() Dim mystring As String mystring = Left(ActiveCell, 1) MsgBox mystring With ActiveCell ..Replace what:=mystring, replacement:="" End With End Sub Andy wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
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 "Andy" wrote: 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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
ActiveCell.Value = Right(ActiveCell.Value, Len(ActiveCell.Value) -1)
That did it. Thanks everyone! Andy |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
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) "Andy" wrote: ActiveCell.Value = Right(ActiveCell.Value, Len(ActiveCell.Value) -1) That did it. Thanks everyone! Andy |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
Just a note. Vba's Mid function works a little differently that the
worksheet version. ActiveCell = Mid$(ActiveCell, 2) -- Dana DeLouis Win XP & Office 2003 "Andy" wrote in message ... ActiveCell.Value = Right(ActiveCell.Value, Len(ActiveCell.Value) -1) That did it. Thanks everyone! Andy |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
I test for the character I want to delete, but Mid is a little more
elegant. 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) "Andy" wrote: ActiveCell.Value = Right(ActiveCell.Value, Len(ActiveCell.Value) -1) That did it. Thanks everyone! Andy |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delete first character in ActiveCell
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Need Help with ActiveCell.EntireRow.Delete | Excel Discussion (Misc queries) | |||
Need Help with ActiveCell.EntireRow.Delete | Excel Discussion (Misc queries) | |||
If activecell.column = variable then activecell,offset (0,1) | Excel Discussion (Misc queries) | |||
Delete rows from activecell | Excel Programming | |||
Delete the row where the activecell is located with VBA | Excel Programming |