• Answers
  • Web
Personalize Yedda, (And make Danny Happy)
People ask & answer about almost everything. Tell us what you're interested in... So we can personalize Yedda especially for you
I'm interested in:

Macro to add number to range..HELP!

I need to create an excel macro that adds a 32 to the beginning of each number in a range of cells.  I have a range of >1500 cells.  So far I have used the following macro, but it only does one cell at a time:

Sub AddToCell()     'ActiveCell.Value places the value or formula into the active cell     'on the active worksheet.     '     'ActiveCell.Value returns the value in the active cell of the active     'window.     '     'InputBox calls up the Excel input box for you to type in the number     'to be added to the original value. Val takes the text string     'returned from the input box and turns it into a number.       ActiveCell.Value = ActiveCell.Value + _         Val(InputBox("3100", default:=1)) End Sub Any help would be appreciated!

Share Send to a friend Watch Report
 
 

Posted Answers

 
10 helpful answers

You'll need a loop to go through cells. Here is my suggestion: Sub AddToCell() 'Do starts a loop Do 'Here is your original macro row ActiveCell.Value = ActiveCell.Value + Val(InputBox("3100", default:=1)) 'Select next cell ActiveCell.Offset(1, 0).Select 'Loop ends here if next cell has no value entered Loop Until IsEmpty(ActiveCell.Value) End Sub I don't know, why you are using input box here. If you need to add numbers 32 in front of all numbers, I would automate that also, in example like this: Sub AddToCell3() 'Do starts a loop Do 'Here is your original macro row ActiveCell.Value = "32" & ActiveCell.Value 'Select next cell ActiveCell.Offset(1, 0).Select 'Loop ends here if next cell has no value entered Loop Until IsEmpty(ActiveCell.Value) End Sub

Posted 2009-09-16T04:55:58Z
EscApe was invited by Yedda to answer this question.

Sign in to participate

Got an answer for DrewBurn? Would you like to comment on the posted answers, or vote for the one which you think is the best?

Sign up for a free account, or sign in (if you're already a member).

Explore Related Questions

Other people asked questions on similar topics, check out the answers they received:


Q:

Sample Succession PLans in Excel FOrmat

Does anyone have ideas for excel sheet for succesion plans?
Submitted by careymm   4 months ago.
  • viewed 164 times


Q:

Excel 2007 - currency format part 2

i have a problem with the way Excel 07 interpretes Windows regional settings. With the Excel 07 file open and Windows regional ...
Submitted by harperj   1 year ago.
  • viewed 786 times


Q:

Excel 2007 - currency format

Excel 2007 automatically converts numerical values into the currency format. Every time I set the cells to "general" format it ...
Submitted by drabsv   3 years ago.
  • viewed 1061 times
Last answer posted 3 years ago by drabsv



» More...

Explore Related Posts in Forums

copy current excel data to a new excel file

HI, anyone know how to copy a range of data from current excel to a new excel or sheet1 to sheet2 ? how to read columns? Lets say, range A1:A15, A17:A27, etc.. to a new excel file/sheet. You can copy a sheet, by right click the sheet tab at the botttom of the excel workbook

Unable to open Excel 2003 files with Excel 2007

I have recently installed Excel 2007.My OS is windows Vista I am unable to open excel files of previous versions directly by clicking. To open a previous version file, I have to open Excel 2007 first Seems to be a file association issue (unless there's a specific error from Excel 2007,which you

Pivot Table: How to block users from opening the Excel Workbook in Excel ...

I habe used the Excel Services to show Users of the SharePoint site a Pivot Table. I would like the users not to be able to open the Excel Workbook in Excel itsself. How can I do this? setting in the workbook itself that affests this?You can uncheck the Open in Excel, Open Snapshot
» More...
Powered by
Feed - Subscribe to changes to this Q&A Blog
ADVERTISEMENT
  • Answers
  • Web
Copyright © 2006-2009, Yedda Inc. and respective copyright owners · CC License