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
 

Some videos you may like

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".

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
You could use a macro if you really want to, but the easiest way would be just to use a formula ie =Right(A1,Len(A1)-4) , and copy/pastespecial the values onto the original range.

If you want a macro, paste the code that you already have, and I'll help you out.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
Derek

Do you really need a macro to do this?

Can you not use worksheet functions like MID, LEFT and RIGHT?

What do you mean by a list of files, are they in cells on a worksheet?

Can you post what code you are currently using and an explaination what you want it do do?
 

Nimrod

MrExcel MVP
Joined
Apr 29, 2002
Messages
6,259
Sub Left4Trim()
For Each Strng In Columns("A:A").SpecialCells(xlCellTypeConstants, 3)
Strng.Value = Right(Strng, Len(Strng) - 4)
Next Strng
End Sub


............ :wink:
 

krazyderek

Board Regular
Joined
Feb 17, 2005
Messages
60

ADVERTISEMENT

yup each name is in it's own cell, going down on colum. but each name has numbers next to it like this..

21. buddy dude guy
22. doodedoodedoo
23. lalalalal

i just need something that will quickly delete the 2 numbers, the decimal, and the space and just leave me with this...


buddy dude guy
doodedoodedoo
lalalalal

doesn't have to be a macro, just thought that was the easiest way to do it as i'm fairly unfamiliar with excel other then a couple of math formulas...

oh ya... there's about 80 cells..
 

sweater_vests_rock

Well-known Member
Joined
Oct 8, 2004
Messages
1,657
Derek.

If the cells are non-formulaic,

Sub DeleteFirstFour()
For Each C In Cells.SpecialCells(xlCellTypeConstants)
If C.Value <> "" Then
C.Value = Mid(C.Value, 5, Len(C.Value) - 4)
End If
Next C
End If

WARNING!!! This deletes the first four from ALL cells. Change Cells. to Range("A:A"). for the first column only.
 

krazyderek

Board Regular
Joined
Feb 17, 2005
Messages
60

ADVERTISEMENT

oh cool 2 different ways. ok i'll give them a try now, thank you very much !!
 

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
Just a thought.... Should you not really delete all the characters up until
, and including, the space? You say your list is about 80 long. If it increases (is this possible?) to over 99 then, I assume, you will want to delete the first 5 characters of some cells ie "123. Blahblah"
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
Derek

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

krazyderek

Board Regular
Joined
Feb 17, 2005
Messages
60
it's just a list of 98, and i can just do the first 10 on my own....

hmmm is there a more complexe one that will remove the single, double and triple digit numbers from a list? now that i think about it, chances are next time the list is going to be much bigger... only problem is there may be numbers mixed in with the names them selves too..
 

Watch MrExcel Video

Forum statistics

Threads
1,122,224
Messages
5,594,915
Members
413,952
Latest member
JGer

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
Top