Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Need help with simple vba script for Excel macro
Closed Thread
Old 07-12-2005, 01:12 PM   #1 (permalink)
 
Ultra Techie

Join Date: Mar 2005

Posts: 500

smileygladhands

Unhappy Need help with simple vba script for Excel macro

I have a column for about 4000 accounts on Excel. Each of them needs to have ('0 ) - without the parenthesis - added to the beginning of the account. I tried recording a macro that recorded me selecting the beginning of the text in the cell and typing '0. However, when I run the macro on other cells it replaces the new account number with all of the text of the cell that I recorded the macro in.
Here's the script:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Sub add_0()
'
' add_0 Macro
' Macro recorded 07/12/2005 by a371261
'
' Keyboard Shortcut: Ctrl+q
'
ActiveCell.FormulaR1C1 = "'069049000"
Range("C11").Select
End Sub
Sub Macro7()
'
' Macro7 Macro
' Macro recorded 07/12/2005 by a371261
'
' Keyboard Shortcut: Ctrl+t
'
Application.CommandBars("Stop Recording").Visible = False
Application.WindowState = xlMinimized
Application.Goto Reference:="add_0"
End Sub
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Obviously, I'm not very proficient with vbase... how can I edit the above so when I highlight the rest of the cells, it places '0 at the beginning of each account number?

Thanks for any help.

__________________
<a href=\"http://www.democracynow.org\"><img src=\"http://i5.photobucket.com/albums/y165/smileygladhands/linkbanner468x60.gif\" border=\"0\"></a>
\"All over the place, from the popular culture to the propaganda system, there is constant pressure to make people feel that they are helpless, that the only role they can have is to ratify decisions and to consume.\" -Noam Chomsky
smileygladhands is offline  
Old 07-14-2005, 03:40 AM   #2 (permalink)
 
Junior Techie

Join Date: Feb 2005

Posts: 50

foxhound

Default

the way i would do it is make it check if there's something in the cell. if there is, then cut the contents out. then add the 0 you want, then paste it back. then move to the cell below it. and repeat the process (use a do while selected cell <> "" ) .
should work.
foxhound is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On