Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Delete first character in ActiveCell

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

That did it.

Thanks everyone!

Andy




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with ActiveCell.EntireRow.Delete Ayo Excel Discussion (Misc queries) 4 July 20th 08 11:07 AM
Need Help with ActiveCell.EntireRow.Delete Ayo Excel Discussion (Misc queries) 8 July 19th 08 04:45 PM
If activecell.column = variable then activecell,offset (0,1) Battykoda via OfficeKB.com Excel Discussion (Misc queries) 1 October 2nd 07 08:05 PM
Delete rows from activecell al Excel Programming 3 September 27th 04 01:07 PM
Delete the row where the activecell is located with VBA Tim Zych[_2_] Excel Programming 0 July 19th 03 03:57 AM


All times are GMT +1. The time now is 01:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"