Solved

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

Posted on 2014-02-11
5
4,511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

737 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