add cells

I have this to start

Sub Total()
Range("D1").Value = Range("E1").Value + Range("F1").Value

What do I have to add to this so it continues down 500 rows (D500 = E500 
+D500)

Thanks in advance!
0
Utf
3/25/2010 5:55:01 PM
excel.programming 6508 articles. 2 followers. Follow

6 Replies
793 Views

Similar Articles

[PageSpeed] 58

Sub makeformula()
For i = 1 To 500
 Cells(i, "d").Value = Cells(i, "e") + Cells(i, "f")
Next i
End Sub

-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Kristen" <Kristen@discussions.microsoft.com> wrote in message 
news:A79F9080-20FB-4603-9716-8E4CB7923C36@microsoft.com...
>I have this to start
>
> Sub Total()
> Range("D1").Value = Range("E1").Value + Range("F1").Value
>
> What do I have to add to this so it continues down 500 rows (D500 = E500
> +D500)
>
> Thanks in advance! 

0
Don
3/25/2010 6:09:47 PM
Copy this to your public code module1 in the VBE.  It will add columns.E and 
F for each row that has a value in column E of the active sheet.


Sub Total()
    Dim lr As Long, sh As Worksheet, rng As Range
    Set sh = ActiveSheet
    lr = sh.Cells(Rows.Count, 5).End(xlUp).Row
    Set rng = sh.Range("D1:D" & lr)
    For Each c In rng
        c = c.Offset(0, 1) + c.Offset(0, 2)
    Next
End Sub

"Kristen" <Kristen@discussions.microsoft.com> wrote in message 
news:A79F9080-20FB-4603-9716-8E4CB7923C36@microsoft.com...
>I have this to start
>
> Sub Total()
> Range("D1").Value = Range("E1").Value + Range("F1").Value
>
> What do I have to add to this so it continues down 500 rows (D500 = E500
> +D500)
>
> Thanks in advance! 


0
JLGWhiz
3/25/2010 6:13:44 PM
It seems that one option would be to put the formula = E1 + F1 in cell D1.  
But maybe that is not what you want in which case you could use this routine:

Sub testing()

Dim lng As Long

For lng = 1 To 500
Range("D" & lng).Value = Range("E" & lng).Value _
+ Range("F" & lng).Value
Next lng

End Sub

Tom (is my name not part of code)
0
Utf
3/25/2010 6:37:01 PM
Hi Tom,
Thanks for answering my question. I get a "Compile Error Invalid outside 
procedure" error when I tried this. Yes, the formula method would work, 
however, I also need to delete the contents of columns E and F while keeping 
the added values.

"tompl" wrote:

> It seems that one option would be to put the formula = E1 + F1 in cell D1.  
> But maybe that is not what you want in which case you could use this routine:
> 
> Sub testing()
> 
> Dim lng As Long
> 
> For lng = 1 To 500
> Range("D" & lng).Value = Range("E" & lng).Value _
> + Range("F" & lng).Value
> Next lng
> 
> End Sub
> 
> Tom (is my name not part of code)
0
Utf
3/25/2010 6:48:01 PM
Sub makeformula()
For i = 2 To 22
Cells(i, "d").Value = Cells(i, "e") + Cells(i, "f")
Next i
Columns("e:f").clearcontents 'Delete
End Sub

-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Kristen" <Kristen@discussions.microsoft.com> wrote in message 
news:D8442729-E1AF-418D-A3AE-5688FB424131@microsoft.com...
> Hi Tom,
> Thanks for answering my question. I get a "Compile Error Invalid outside
> procedure" error when I tried this. Yes, the formula method would work,
> however, I also need to delete the contents of columns E and F while 
> keeping
> the added values.
>
> "tompl" wrote:
>
>> It seems that one option would be to put the formula = E1 + F1 in cell 
>> D1.
>> But maybe that is not what you want in which case you could use this 
>> routine:
>>
>> Sub testing()
>>
>> Dim lng As Long
>>
>> For lng = 1 To 500
>> Range("D" & lng).Value = Range("E" & lng).Value _
>> + Range("F" & lng).Value
>> Next lng
>>
>> End Sub
>>
>> Tom (is my name not part of code) 

0
Don
3/25/2010 7:11:44 PM
I don't know why you get the compile error, maybe it is a 2007 issue as I run 
excel 2003.  I have added the code to clear the contents of columns D & F 
here, but you might want to try Don Guillett's code.


Sub testing()

Dim lng As Long

For lng = 1 To 100
Range("D" & lng).Value = Range("E" & lng).Value + Range("F" & lng).Value
Range("E" & lng, "F" & lng).ClearContents
Next lng

End Sub

0
Utf
3/25/2010 7:25:01 PM
Reply:

Similar Artilces:

Add Lookup Fields to Entity
I need to add 4 "technical contact" fields (which would lookup the Contact entity) to the CONTRACT form. Is this possible? I've found it difficult to figure out what to do first. Thanks in advance, Brandon Not possible. You cant have multiple lookups for the same entity. You also cannot create new relationships between two system entitites. This will work in 4.0 Not possible, Pezman. N:M relationships are not possible in 3.0 yet. There is a alternative solution: a new entity to act as an N:M relationship. In your case, Contract/Contact. This entity has two 1:N relations...

Run macro via cell value
Is it possible to run a macro based on the value of a cell. Say for example A1 contains the word "run" can that word be the trigger to automatically run a macro? Pat Hi Pat A worksheet formula can not trig a macro. No way. But a worksheet has several events; macros that run when certain things happen. There is an event firing when you enter something into a cell, another when the sheet recalculates, ... see http://www.cpearson.com/excel/events.htm for more on this. HTH. Best wishes Harald "Pat" <glass_patrick@hotmail.com> skrev i melding news:OV4A5QBUFHA.58...

Cells #3
How I can make a cell contact with another cell on another sheet and it will changes when day changes. example I have cell A1 sheet1 contact with cell A2 sheet 2 and cell A1 sheet 2 is the date when the date change A1 sheet 1 will auto change to B2 sheet 2 and the date = B2 Ali, You could use the CHOOSE function which returns the nth value. For example, =CHOOSE(3, A2, B3, C4, D5, E6) will return A4, the third value in the array {A2, B3, C4, D5, E6}. This works well if the cells are not contiguous, but you are limited to 30 values if I remember well. If your values are in contiguous ce...

Linked cells within a wokbook
I have a workbook with about 40 worksheets, there are links between the workbooks that sporadically do not update. I have checked the links when they freeze and have been unable to identify the cause. Eg cell c76=a number from a lookup table, is referenced throughout the workbook, in various functions. When c76 changes the functions freeze on the previous output of c76. The lookup table works and c76 changes accordingly, but the related functions do not. WHY Thanks in advance ...

Excel Add Ins
What is the name of the template wizard with Data Tracking (Excel. I can not locate the add in template wizard with Data Tracking in Office 2003 Hi Richard You are not the only one<g> The Add-in is working in 2003 only the install file is not working. Copy the xla file from a PC with 2002 to the PC with 2003 and it will work(use Tools>add-ins to browse to the file in Excel) -- Regards Ron de Bruin http://www.rondebruin.nl "Richard" <Richard@discussions.microsoft.com> wrote in message news:193C5DFD-578D-48F7-B9D6-9FEF5BDCEB64@microsoft.com... > What is t...

form cell question in Ver2000
I have a large sheet with email addresses in a column that only displays "yes" with the letters in a gray shaded area. When I hover over the cell the underlying email address becomes visible. I need to find a way to create a column of the email addresses. Any help will be appreciated. James It sounds like someone added hyperlinks to your worksheet. If you select the cell and do Insert|Hyperlink, do you see the email address in a nice dialog? If yes, you can use a user defined function to extract that link (including email address). Saved from a previous post: One way to e...

Add on
Hello, Here is a scenerio. A client is buying 1lb of ham. It is put on a waxed paper then wrapped into a white paper and then put into a shopping bag. The usage of shopping bag is 100% cases the usage of paper is only with certin categories of sales. Same with the waxed paper. Question: Is there a way of associating wax paper, white paper and shopping bags in a way so with every sale a piece of paper gets deducted from inventory and one bag is deducted from inventory? I would like to run a report every so often and see if I need to purchase any supplies. Kits and assembly do not work...

add a row or column to a single cell in exel
I am trying to split a single cell into 2 rows can you help If I understood correctly you want to enter an entry in two lines in a cell at appropirate place hit lt+enter and again hit enter for e.g venkat (alt+enter) raman(enter) "trev" <trev@discussions.microsoft.com> wrote in message news:89B2C15C-057F-43B9-8282-37923D5EA397@microsoft.com... > I am trying to split a single cell into 2 rows can you help ...

Hyperlink many cells
I am trying to link many cells on one worksheet to corresponding cells on another. I have two worksheets, one with item price information and another with physical item information. Both sheets share a common "number" field. Each item has unique number that is referenced on both sheets. I want to set up a hyperlink so that when the when any cell in the number field in the price file is clicked, it lgoes to the cell with that same value in the number field on the other sheet. I can do this by one cell at a time by right clicking the cell, adding the hyperlink and setting...

way to delete add. fr. auto. email add. function?
Is there a way to delete old or no longer used email addresses that appear in the drop down box when I am addressing a new email? Shebubba wrote: > Is there a way to delete old or no longer used email addresses that appear in > the drop down box when I am addressing a new email? That is the nickname cache. Search and delete the .nk2 file. That's the cache for nicknames (i.e., your manually entered e-mail addresses). If you only want to delete some of them, highlight an entry and hit the delete key. If that doesn't work, use Nirsoft's NK2 Viewer utility (it e...

POS 2009 Add-In: Populating a Task Pad
I would like to create a custom application that has the ability to maintain the items that are on certain Task Pads within POS 2009. These items would all be regular menu items (ex: hamburger, hot dog, french fries, etc) and not functions. For example, if a task pad was supposed to allow the cashier quick access to daily specials, then this custom application would need to be able to clear the task pad each day and add the items for that day. Is this going to be possible? Please provide some guidance. Thank you, Sean This is a multi-part message in MIME format. ------=_NextPart_00...

my formated column is displaying one cell incorrectly
I have a spreadsheet with 4 columns; the 4th columns is a formula going across the 3 columns a+b-c = d with d preferably equally zero. When I format column d almost all of the columns that equal zero display as a dash (preference). However periodically one or two of the rows will display as 0.00 and I can't seem to get the formatting to change to the dash. I have tried to reformat all columns all other cells and to no avail. Has anyone else run into this issue and if so how have u solved it. The only way I can solve it is to actually put a zero in the cell. If the numb...

Referencing cells
Hi, I posted earlier but got no response. I think my explanation then was too difficult to understand so I'm trying again. I hope this time it is more easily understandable In Workbook 1 "Exp_06.xls", I have a column of numbers starting on row 23 as shown. 23 1000 24 500 etc.etc. Each cell in the column is named, for example cell "A23" is named "AutoInsurance" and cell "A24" is named "AutoGasoline". The formula bar for each cell contains only the number in the cell and does not reference the cells name. In Workbook ...

Add-in cannot be loaded OL07
Every time I open Outlook 2007 I get an error message regarding an add-in 'DCCExtensions' (DCCEXT32.DLL). It says the add-in cannot be loaded and has been disabled by Outlook. I've been getting this message ever since I uninstalled Winfax. How do I make this error stop appearing? Thanks. -- kapibarra Remove the addin from OL by using Trust Center, Addins. http://office.microsoft.com/en-us/outlook/HA100341271033.aspx#14 "kapibarra" wrote: > Every time I open Outlook 2007 I get an error > message regarding an add-in 'DCCExtensions' (DCCEXT32.DLL). ...

Replacing Cell Contents
Hello Folks Is there any way via formula to replace the contents of Cell A1 with a formula written in B1 or any other cell? Thanks Hi no way to achieve this with formulas. Formulas can only return values but not change other cells -- Regards Frank Kabel Frankfurt, Germany Bob Leathers wrote: > Hello Folks > > Is there any way via formula to replace the contents of Cell A1 with a > formula written in B1 or any other cell? > > Thanks Thanks for your reply. Is there then a way, via macro, to continually check to see if the value in cell A1 has changed? If so change th...

How do I increase the text size of an Excel cell?
Hi guys, Situation: I had a memo size field in MS Access. When I copied and pasted it into an MS Excel cell the text gets truncated? I can't believe that Microsoft has had about 5-6 versions of Excel and hasn't fixed this simple problem. Mike Web Developer and Catholic Apologist http://www.faithfulchristians.net I think this is by design. Not everyone would want the whole column resized because of a single truncated cell. "Mike_Humphrey" <Mike_Humphrey@discussions.microsoft.com> wrote in message news:79662172-C13B-4708-AAF4-B02511AD79AA@microsoft.com... > H...

SumIFS Cell
I am trying to reference a cell in a formula and I would like to say anything greater then cell J2 but when I input this it searches for text. =SUMIFS($B$2:$B$27,$A$2:$A$27,"000001",$C$2:$C$27,>D2) A B C D 1 00001 100 40248 40248 2 12001 150 40237 3 15001 200 40237 4 00001 150 40290 5 00001 50 40350 I would like the total to return 200 because Cell C5 and C4 are larger than Cell D1 in respect to the Sku number I would like to sum. But when I put in >J2 it enters “>J2” and it won’t return a value other then 0. (If I put in just D2 then it returns a valu...

Format text to add character
I have two fields that should match, but one includes special characters while the other does not. Example: Field1 00ABCD123456123 Filed2 00/ABCD/123456/123/SBZ I need to find records where these two fields don't match, either by changing the display of one of them, or a query to compare Field1 character 7-15 with Field2 characters 9-14, 16-18. Hope this makes sense. Can anyone help? Thanks! Take a look at the following from the Access Help file it might be what you're looking for... Extract a part of a text value The following table lists examples of expressions that ...

Rank a Column + 1 cell from 2nd Col
I have 6 columns: A B C D E F 274 1 269 ? 279 ? 275 2 270 ? 280 ? 276 3 271 ? 281 ? 288 4 283 ? 293 ? Column B represents a simple 'Rank' of Column A In the first row of column 'D' I want the rank of the 269 in relatio to the figures in column 'A' which equals 1. I also want the rank o 270, 271 & 272 in relation to their position on Column 'A' - whic would equal 1, 1, 4 In Column 'F' I want the rank of those figures in 'E' relation to th values of column 'A'. Which would equal 4, 4, 4, 5 Any help would ...

Add File menu to custom toolbar
Hi All, I am trying to add the 'File" menu and "Window" menu of the Standard Toolbar to a custom toolbar but failing miserably! I think it should look something like: Sub AddMenuTitles() Application.CommandBars("MyCustomMenu").Controls.Add("File) Application.CommandBars("MyCustomMenu").Controls.Add("Window") End Sub Can anybody help please Regards Michael Sub test() AddMenuTitles True ' or false to delete End Sub Sub AddMenuTitles(bAdd As Boolean) Dim cbr As CommandBar Dim cbP As CommandBarPopup ...

How does excel note a newline (ie new line but in same cell)
Version: 2004 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel Hi <br> Have legal transcription i need to manipulate partly in excel on mac. want each cell to be one question or answer in deposition, but can't allow excel to wrap the text of the question or answer, which is typically several lines, as in depositions each line is numbered and i want to preserve the numbers matching the lines. so i would like to manually add the character/formatting in my text editor before i bring the text back into excel. <br><br>or perhaps i can write an excel macro or f...

Cell Expansion
In an excel document, I have wrap text turned on, but the cell doesn't resize to accomodate the text. I tried format row autofit as well as double clicking on the bottom of the row, but nothing is happening. I had to widen the row myself by dragging the row bar down. Is there something else I need to turn on or off? Any help is appreciated. Thanks. Kirk Is that text in a merged cell? If yes, then merged cells don't react nicely to autofit? Jim Rech wrote a macro called AutoFitMergedCellRowHeight that you may like: http://groups.google.com/groups?threadm=e1%241uzL1BHA.1784%...

add a DC in a LegSite
Hi, In the disaster recovery plan we want to create a leg site and put a DC in it. Here are some questions on how to achieve this smoothly. 1. Should I create the new site/subnet first and then promote a server in that subnet/site to DC, or should I promote a server in existing site/subnet and then move this DC to the new site/subnet? 2. When promoting a server to DC, should the server be a member server (already joined the domain) or just a workgroup member (no domain membership)? 3. The DC will be an AD-integrated DNS server. Should I install the DNS component (but not confi...

Cell outline
When I set some cells with a `thicker` outline or have a cell colour and then move (drag) the contents of the cell, the outline and cell colour moves with it. Is there a way to `lock` the outline and fill colour to that particular cell so it is only the typed contents that move. thanks -- http://www.freewebs.com/turkeyrent/ You could rightclick and drag and then copy as values. But then you'd have to go back to the original cell and clear the contents. And since you're doing a copy, any formulas that refer to the original cell will still refer to the original cell. Copy an...

How can I add the customer's PO# to the drop-ship Purchase Order?
Our purchasing agent would like to be able to have the customers PO# from the Sales Transaction Entry screen show up on the PO's. Is this doable in Report Writer or can it not be done? We are using GP v9.0. As I still consider myself a newbie with RW, I would appreciate detailed instructions if possible. Thank you in advance for all responses. It is not possible thru traditional table relationships in Report Writer. Let me explain: you can certainly link the Purchase Order Work table to the SOP_POLink table and the SOP_POLink table to the SOP Transactions Work table, but will...