Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / March 2008

Tip: Looking for answers? Try searching our database.

Macros

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian - 18 Mar 2008 22:27 GMT
I am trying to create the simplest of macros. I just want to delete the first
4 characters of a cell, and then have it repeat that process for about 350
cells.  Everytime I hit record and give it a name and hot key. I preform the
steps of deleting 4 characters in a cell and hit enter to goto the next cell.
I hit stop recording and then try to run the macro, which at this point does
not work.. Can ANYONE HELP. What am I doing wrong

Thanks
Brian

brian_watson@interact.ccsd.net
Ken Hudson - 18 Mar 2008 22:39 GMT
Hi Brian,
Assuming that you have data in column A and that the first cell is A1, the
following macro should do the job. It will do nothing if there are four or
fewer characters in a cell.

Option Explicit
Dim CountRows As Double
Dim Iloop As Double
Sub DeleteCharacters()

'Turn off warnings, etc.
Application.ScreenUpdating = False
Application.DisplayAlerts = False

CountRows = Cells(Rows.Count, "A").End(xlUp).Row
For Iloop = 1 To CountRows
   If Len(Cells(Iloop, "A")) > 4 Then
       Cells(Iloop, "A") = Right(Cells(Iloop, "A"), _
       Len(Cells(Iloop, "A")) - 4)
   End If
Next Iloop
   
'Turn off warnings, etc.
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Signature

Ken Hudson

> I am trying to create the simplest of macros. I just want to delete the first
> 4 characters of a cell, and then have it repeat that process for about 350
[quoted text clipped - 7 lines]
>
> brian_watson@interact.ccsd.net
Don Guillett - 18 Mar 2008 23:19 GMT
Sub trimleftfour()
lr = Cells(Rows.Count, "f").End(xlUp).Row
For Each c In Range("f2:f" & lr)
c.Value = Right(c, Len(c) - 4)
Next c
End Sub

Signature

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com

>I am trying to create the simplest of macros. I just want to delete the
>first
[quoted text clipped - 11 lines]
>
> brian_watson@interact.ccsd.net
Gord Dibben - 19 Mar 2008 05:49 GMT
What are you doing wrong.........?

You cannot record or run a macro while in Edit mode which is the mode you are in
when deleting the first four characters.

See the macros from Don and Ken to get what you want.

Gord Dibben  MS Excel MVP

>I am trying to create the simplest of macros. I just want to delete the first
>4 characters of a cell, and then have it repeat that process for about 350
[quoted text clipped - 7 lines]
>
>brian_watson@interact.ccsd.net
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.