LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Better way to apply a formula

Below is code that copies a formula down a worksheet until it reached the end
of the dataset. The formula is a sumif with variables that move as the
formula is copied down.

It runs fine, but takes about 2 minutes to complete around 1000 rows of
data. I am thinking there has to be a better way to do this. Any
suggestions?

Dim u1 As Range
Dim u2 As Range
Dim iSum As Range
Dim cSum As Range
Dim i As Integer

Set u1 = Sheet2.Range("N11")
Set u2 = Sheet2.Range("N12")
Set iSum = Sheet2.Range("C12:G12")
Set cSum = Sheet2.Range("C11:G11")

i = 1

Do Until Application.WorksheetFunction.Sum(iSum) = 0

u2 = "=IF(SUM(" & iSum.Address(False, False) & ")=SUM(" &
cSum.Address(False, False) & ")," & u1.Address(False, False) & " ," &
u1.Address(False, False) & "+" & i & ")"

Set u1 = u1.Offset(1, 0)
Set u2 = u2.Offset(1, 0)
Set iSum = iSum.Offset(1, 0)
Set cSum = cSum.Offset(1, 0)

Loop

Running 2007 with XP SP2.

Thanks!
PJ
 
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
How to... apply the same formula to every cell? klee Excel Discussion (Misc queries) 3 February 3rd 09 06:24 PM
automatically apply formula to new row CrazySwayze Excel Programming 1 May 10th 07 04:28 PM
Apply Names in Formula Dave Unger Excel Programming 2 January 10th 07 04:20 AM
HOW DO I APPLY A FORMULA FOR AND ENTIRE ROW? jcpayne Excel Worksheet Functions 2 July 19th 06 06:02 PM
apply formula to other rows ... berti Excel Discussion (Misc queries) 1 December 15th 05 08:30 AM


All times are GMT +1. The time now is 03:51 AM.

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

About Us

"It's about Microsoft Excel"