Solved

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

Posted on 2014-02-11
5
4,286 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 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

821 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