How do you LOOP UNTIL a formula result equals a certain value?

RobShorter

New Member
Joined
Jul 8, 2010
Messages
18
Hi,

I'm using the 'Do' and 'Loop until' vba functions so that I can copy a formula down to a certain cell in the column. The only way of identifying this 'certain cell' is if I were to evaluate a formula based on the sum of a range in the column next to it, sum(RC[1],R4C100)=0, where the range is from a variable cell RC[1] to a fixed cell R4C100.

How do I write this in VBA code?

Thanks,
Rob
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
That doesn't make it any clearer unfortunately. What would your SUM formula be now, and why the comma in it?
 
Upvote 0
Here is the sequence of events required:

1. a formula is written in cell C5
2. This formula is copied down column C until the sum of values from cell DX to D100 = 0, where X is the same row as formula.

e.g.

the formula gets copied to cell C6 if sum(D6:D100)>0
the formula gets copied to cell C7 if sum(D7:D100)>0
the formula gets copied to cell C8 if sum(D7:D100)>0

but

the formula would not get copied to cell C8 if sum(D8:D100)=0

apologies for the previous confusion
 
Upvote 0
Try:

Code:
Sub Test()
    Dim r As Long
    Dim c As Long
    Dim Total As Long
    With Range("C5")
        r = .Row
        c = .Column
        Do
            r = r + 1
            Total = WorksheetFunction.Sum(Range(Cells(r, c + 1), Cells(100, c + 1)))
            If Total = 0 Then Exit Do
        Loop
        .AutoFill Destination:=.Resize(r - .Row)
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,735
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top