Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro that stips characters from fields in a column 1

Status
Not open for further replies.

paul123456

Technical User
Apr 29, 2002
518
US
Can someone help me out. Im looking to create a macro for excel that will strip out the first 2 characters in a text column for all records. say the column will always be D. is there a way that a macro will strip out only the first 2 letters of the record in all fields under column D?

Thanks, PAUL

 
Select Col D, do data / Text to Columns / Fixed Width

Put a divider after the second character and hit next. With the first column selected in the dialog box, choose the 'Do Not Import this column' option. Hit next and OK and you are done.

Regards
Ken...............

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]

----------------------------------------------------------------------------
 
OMG that is sooo neat...i never knew that way in there...thats a really good feature!

Thanks, PAUL

 
If you really want a macro though, you can also just record yourself doing what I just said, and it will give you something like this:-

Sub Macro1()

Columns("D:D").select
selectionTextToColumns Destination:=Range("D1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 9), Array(2, 1)), TrailingMinusNumbers:=True
End Sub

A little bit of editing tidies it up somewhat and gives you this

Sub Strip2fromColD()

Columns("D:D").TextToColumns Destination:=Range("D1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 9), Array(2, 1)), TrailingMinusNumbers:=True
End Sub

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]

----------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top