简体   繁体   中英

Goal-seek Macro Loop that skips blanks

I'm very new to VBA. I've been trying to learn by trying, and reading forums, but I'm at a loss.

Sub Macro()

Dim i As Long
    For i = 1 To 100
        ActiveCell.Offset(1, 0).Select
        ActiveCell.GoalSeek Goal:=1, ChangingCell:=ActiveCell.Offset(0, -3)
    Next i
End Sub

This is what I found on the forums more or less, and it works for a column with random numbers, which is good. But I need it to skip blank cells. Alternatively, I need it only apply the macro to visible cells (when filtered).

I've found answers to this question, but I don't know how to insert them into my code.

Sub Macro()

Dim i As Long
    For i = 1 To 100
        If ActiveCell.Value = "" then GoTo here
        ActiveCell.Offset(1, 0).Select
        ActiveCell.GoalSeek Goal:=1, ChangingCell:=ActiveCell.Offset(0, -3)
here:
    Next i
End Sub

Try this

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