PC Review


Reply
 
 
Kristen
Guest
Posts: n/a
 
      25th Mar 2010
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!
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      25th Mar 2010
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
(E-Mail Removed)
"Kristen" <(E-Mail Removed)> wrote in message
news:A79F9080-20FB-4603-9716-(E-Mail Removed)...
>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!


 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      25th Mar 2010
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" & lr)
For Each c In rng
c = c.Offset(0, 1) + c.Offset(0, 2)
Next
End Sub

"Kristen" <(E-Mail Removed)> wrote in message
news:A79F9080-20FB-4603-9716-(E-Mail Removed)...
>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!



 
Reply With Quote
 
tompl
Guest
Posts: n/a
 
      25th Mar 2010
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)
 
Reply With Quote
 
Kristen
Guest
Posts: n/a
 
      25th Mar 2010
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)

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      25th Mar 2010
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
(E-Mail Removed)
"Kristen" <(E-Mail Removed)> wrote in message
news8442729-E1AF-418D-A3AE-(E-Mail Removed)...
> 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)


 
Reply With Quote
 
tompl
Guest
Posts: n/a
 
      25th Mar 2010
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
That document contains too many cells. At this time, spreadsheets inGoogle Docs only support up to 400000 cells Mark Microsoft Excel Misc 0 19th Jan 2011 03:08 PM
copy an intial cells contents into the next series of blank cells ina column freeriderxlt Microsoft Excel Discussion 2 25th Aug 2009 07:47 AM
Excel: match two cells in one sheet to two cells in another and return a third cells value Spence Microsoft Excel Worksheet Functions 2 19th Jul 2005 04:19 AM
Skip cells with TAB/SHIFT+TAB but allow arrow keys/mouse selection of skipped cells Wescotte Microsoft Excel Programming 1 6th Jun 2005 07:00 PM
A calculation to count all cells ='D' where the offset cells in range have dates <= todays date AlanN Microsoft Excel Misc 2 29th Jan 2004 03:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:32 PM.