Solved

Excel VBA - Delete the first character in a cell and move down to next cell

Posted on 2014-02-11
5
3,857 Views
Last Modified: 2014-02-11
I have a "island" of cells.  a9:a230
I would like to have a macro:
1.  Press F2 (edit the cell).
2.  delete the first character in the cell.
3.  Press ENTER
4.  Move down one cell
Repeat steps 1, 2, 3, 4
0
Comment
Question by:brothertruffle880
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:regmigrant
ID: 39850358
Have you tried recording a macro ? turn on the developer tool bar (customise ribbon, select developer in right hand pane) then select the first cell you want to change.

From the developer tab choose record macro and give it a name and a shortcut key.

Follow the sequence you have described (f2,home,del,enter) until step 4 - then stop the macro. you can now use the shortcut key to do them one after another

alternatively put the following formula into a different column (eg b9)
"=mid(a9,2,len(a9))" and copy that down the column.

If you want to just retain the output - not the formula - then select the new column and copy, past special, values
0
 

Author Comment

by:brothertruffle880
ID: 39850410
Using the macro recorder didn't delete the first character of the cell  
The macro recorder re-input the existing cell contents for that one cell.

I need to edit the cell --regardless of the cell contents.
then I need to delete the first character, regardless of it's character.
0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
ID: 39850469
You might try a macro like this:
Sub Stripper()
Dim cel As Range
Application.ScreenUpdating = False
For Each cel In Range("A9:A230")
    cel.Value = Mid(cel.Value, 2)
Next
End Sub

Open in new window

0
 
LVL 80

Expert Comment

by:byundt
ID: 39850489
You can also do it using the Data...Text to Columns menu item:
Sub StripFirstCharacter()
Range("A9:A230").TextToColumns Destination:=Range("A9"), DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 9), Array(1, 1)), TrailingMinusNumbers:=True
End Sub

Open in new window

0
 

Author Comment

by:brothertruffle880
ID: 39850490
Thank you Byundt.  Just what the doctor ordered.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now