Bulk Goal Seek Macro Breaks when encountering Blank Value

BM604

New Member
Joined
Oct 30, 2014
Messages
15
Hello guys,

Been a long time lurker of this amazing site. Lots of great resources.

I need to do a goal seek on a large excel file line by line. I found the following Macro module that helps automate the process:

Code:
Sub BulkGoalSeek()
   Dim C       As Range
   For Each C In Range("A2:A10")
      C.Offset(0, 1).GoalSeek Goal:=C.Offset(0, 2), ChangingCell:=C
   Next C
End Sub

Please see the image of my doucment here: http://uploadpie.com/SQmvm

Here you can see I have the macro set to run from A2 to A10. You will notice that there are gaps in the data in my file and between rows 6 to 8 the cells are blank. The fact these cells are blank in effect "breaks" the macro. I get the error: Run-time error '1004: Reference is not valid.

How can I get this to continue to run from A2 to A10 by ignoring the blanks?

Any direction is greatly appreciated. Thank you everyone.

Edit: Running isblank(cell) on the "blank cells" that break the macro comes up FALSE. If I make a formula =A6="" that will report as true though. Just wanting to clarify if it makes a difference.
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi, welcome to the forum!

Not tested, but you could try:
Code:
Sub BulkGoalSeek()
Dim C       As Range
For Each C In Range("A2:A10")
    If C.Value <> "" Then
        C.Offset(0, 1).GoalSeek Goal:=C.Offset(0, 2), ChangingCell:=C
    End If
Next C
End Sub
 
Upvote 0
Wow I think that just worked out on my initial test run! Thanks so much FormR! I hope you have a great weekend my friend.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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