simple macro help (but i'm a newb)

krazyderek

Board Regular
Joined
Feb 17, 2005
Messages
60
i have a list of files in excel, i just want to get rid of the numbers at the begining of the cell. so i tried to make a macro that takes a cell and just delet's the first 4 characters then goes on to the next. What happened was it did do this, but it kept replacing what was in the next cell with what was in the very first cell when i recorded the macro.... not really sure how to make a macro start by accepting what ever "may" be in the cell and just making it deleting the first 4 characters in the cell.

Thanks, Derek
 
Here is a modification of Nimrod's code above, which will remove all characters to the left of the first (if any) period (.):

Code:
Sub Left4Trim()
For Each strng In Columns("A:A").SpecialCells(xlCellTypeConstants, 3)
    n = InStr(1, strng.Value, ".")
    If n <> 0 Then strng.Value = Trim(Right(strng, Len(strng) - n))
Next strng
End Sub
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Norie said:
Derek

Why not try Data>Texts to Column... Delimited and select Other and enter '.'?

hmm that also kind of worked.. but these are file names.. and have several dots in them, sometimes dots are used instead of spaces... the output just seems to be a bit to messy.. thanks anyways it was interesting to try
 
Upvote 0
This is flexable ... it will determine where the period is ... :wink:

Sub Left4Trim()
For Each Strng In Columns("A:A").SpecialCells(xlCellTypeConstants, 3)
PeriodPosition = InStr(1, Strng, ".")
Strng.Value = Right(Strng, Len(Strng) - (PeriodPosition + 1))
Next Strng
End Sub
 
Upvote 0
cool thanks craig!!!!!! so... i'm guessing there's no saving in visual basic?? i just pasted it in there (editing my original one) and closed it and it worked..
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top