简体   繁体   中英

VBA Goal Seek Multiple Rows

This should be simple I just can't wrap my head around it

I have 3 columns

ABCI want to run a goal seek on B and C if A has data in it

Range("B3").GoalSeek Goal:=0, ChangingCell:=Range("C3")

I want something similar to this:

  If CellA>0:
     Range("D1").GoalSeek Goal:=0, ChangingCell:=Range("C1")

This could be some 7000 lines worth if that makes any difference

Try this:

Dim rCell As Range

For Each rCell In ActiveSheet.UsedRange.Resize(, 1)
    If rCell.Value <> "" Then
        rCell.Offset(, 3).GoalSeek Goal:=0, ChangingCell:=rCell.Offset(, 2)
    End If
Next rCell

This code sample is based on your last comment above. It will change the cell in column C to give 0 in the formula in the D column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM