?
Solved

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

Posted on 2014-02-11
5
Medium Priority
?
5,431 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 81

Accepted Solution

by:
byundt earned 2000 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 81

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

850 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