#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 68
Default VBA code simpler?


Hi,

I have a feeling that this part of my macro can be done simpler.
But I don't know how.

Range("D" & LastRow + 2).Formula = "=sum(D13:D" & LastRow & ")"
Range("E" & LastRow + 2).Formula = "=sum(E13:E" & LastRow & ")"
Range("F" & LastRow + 2).Formula = "=sum(F13:F" & LastRow & ")"
Range("G" & LastRow + 2).Formula = "=sum(G13:G" & LastRow & ")"
Range("H" & LastRow + 2).Formula = "=sum(H13:H" & LastRow & ")"
Range("I" & LastRow + 2).Formula = "=sum(I13:I" & LastRow & ")"


Thanks in advance for your help.

Cheers,

Harold
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 367
Default VBA code simpler?

Dim chr_ as string

For i = 4 to 9
chr_ = chr(64 + i)
Range(chr_ & LastRow + 2).Formula = "=sum(" & chr_ & "13:" & chr_
& " & LastRow & ")"
next i

is that what you're looking for?

hth

Carlo

On Nov 28, 11:41 am, mohavv wrote:
Hi,

I have a feeling that this part of my macro can be done simpler.
But I don't know how.

Range("D" & LastRow + 2).Formula = "=sum(D13:D" & LastRow & ")"
Range("E" & LastRow + 2).Formula = "=sum(E13:E" & LastRow & ")"
Range("F" & LastRow + 2).Formula = "=sum(F13:F" & LastRow & ")"
Range("G" & LastRow + 2).Formula = "=sum(G13:G" & LastRow & ")"
Range("H" & LastRow + 2).Formula = "=sum(H13:H" & LastRow & ")"
Range("I" & LastRow + 2).Formula = "=sum(I13:I" & LastRow & ")"

Thanks in advance for your help.

Cheers,

Harold


  #3   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default VBA code simpler?

try:
Range("D1:I1").Offset(lastrow + 1, 0).Formula = "=sum(D13:D" & lastrow & ")"


"mohavv" wrote:


Hi,

I have a feeling that this part of my macro can be done simpler.
But I don't know how.

Range("D" & LastRow + 2).Formula = "=sum(D13:D" & LastRow & ")"
Range("E" & LastRow + 2).Formula = "=sum(E13:E" & LastRow & ")"
Range("F" & LastRow + 2).Formula = "=sum(F13:F" & LastRow & ")"
Range("G" & LastRow + 2).Formula = "=sum(G13:G" & LastRow & ")"
Range("H" & LastRow + 2).Formula = "=sum(H13:H" & LastRow & ")"
Range("I" & LastRow + 2).Formula = "=sum(I13:I" & LastRow & ")"


Thanks in advance for your help.

Cheers,

Harold

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 68
Default VBA code simpler?

On Nov 28, 4:00 pm, JMB wrote:
try:
Range("D1:I1").Offset(lastrow + 1, 0).Formula = "=sum(D13:D" & lastrow & ")"



"mohavv" wrote:

Hi,


I have a feeling that this part of my macro can be done simpler.
But I don't know how.


Range("D" & LastRow + 2).Formula = "=sum(D13:D" & LastRow & ")"
Range("E" & LastRow + 2).Formula = "=sum(E13:E" & LastRow & ")"
Range("F" & LastRow + 2).Formula = "=sum(F13:F" & LastRow & ")"
Range("G" & LastRow + 2).Formula = "=sum(G13:G" & LastRow & ")"
Range("H" & LastRow + 2).Formula = "=sum(H13:H" & LastRow & ")"
Range("I" & LastRow + 2).Formula = "=sum(I13:I" & LastRow & ")"


Thanks in advance for your help.


Cheers,


Harold- Hide quoted text -


- Show quoted text -


Thanks works fine.

But I don't get it.

Range("D1:I1").Offset(lastrow + 1, 0).Formula = "=sum(D13:D" & lastrow
& ")"

After reading it I thought it would give met "=sum(D13:"to lastrow")
in the 6 cells. So 6 times the sum of column D.
What does make it change its range to the right column?

Cheers,

Harold
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 947
Default VBA code simpler?

Would this work?

Sub Demo()
Dim LastRow As Long
LastRow = 20

Cells(LastRow + 2, 4).Resize(1, 6).FormulaR1C1 = "=SUM(R13C:R[-2]C)"
End Sub

It reads like this:
Sum from Row 13, same column, to 2 rows above reference, same column.

--
HTH :)
Dana DeLouis
Windows XP & Excel 2007


"mohavv" wrote in message
...

Hi,

I have a feeling that this part of my macro can be done simpler.
But I don't know how.

Range("D" & LastRow + 2).Formula = "=sum(D13:D" & LastRow & ")"
Range("E" & LastRow + 2).Formula = "=sum(E13:E" & LastRow & ")"
Range("F" & LastRow + 2).Formula = "=sum(F13:F" & LastRow & ")"
Range("G" & LastRow + 2).Formula = "=sum(G13:G" & LastRow & ")"
Range("H" & LastRow + 2).Formula = "=sum(H13:H" & LastRow & ")"
Range("I" & LastRow + 2).Formula = "=sum(I13:I" & LastRow & ")"


Thanks in advance for your help.

Cheers,

Harold



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simpler Formula ... 2nd lowest value? Ken Excel Worksheet Functions 17 November 30th 06 01:41 PM
Complex formula vs. simpler GerryK Excel Worksheet Functions 3 December 6th 05 03:33 PM
Excel should have a simpler subtraction formula similar to "sum". Darius Excel Worksheet Functions 5 February 21st 05 11:14 PM
QUESTION- Simpler Way to Add a Data Series to Other Graphs? phil6666 Excel Discussion (Misc queries) 0 February 10th 05 05:57 PM
Another (simpler?) printing problem Abi Excel Discussion (Misc queries) 9 January 13th 05 03:50 AM


All times are GMT +1. The time now is 08:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"