Macro for running goal seek in a column until there is no more data :)

jlernfelt

New Member
Joined
May 30, 2018
Messages
3
Took a VBA course a couple of years ago but man that knowledge went in and out :)

I have x number of rows of data. I would like to run a macro that goal seeks by setting each cell in column R to 0 (zero) by changing the cells in the corresponding row in column Q, until there is no more rows with data. there will be no gaps between rows. I've recorded a macro that runs the goal seek every time I click an assigned button or alternatively runs the macro by shortcut but it would be nice to just make the macro run everything at once. I guess it doesn't take a lot of code.

So..who is up for this easy challenge?

thanks in advance, great forum!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Code:
Sub GoalSeekToZero()
Dim Adjust As Range
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
For Each Adjust In Range("Q2:Q" & Cells(Rows.Count, "R").End(xlUp).Row)
    Adjust.Offset(0, 1).GoalSeek goal:=0, changingcell:=Adjust
Next Adjust
With Application
    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With
End Sub
 
Upvote 0
Hi

Maybe You can use this code snip, I use it every time I must loop through lots of rows.

Set AktCel_opt = AktSht.Range("R1")
Set NxtCel_opt = AktCel_opt.Offset(1, 0)

Do While Not IsEmpty(AktCel_opt)
Set NxtCel_opt = AktCel_opt.Offset(1, 0)

'************************************************
' Here is the code You wants to run for every row
' Could bee a new loop change the Q- cell until
' R- is zero
'*************************************************


Set AktCel_opt = NxtCel_opt
Loop
 
Upvote 0
Hi

Maybe You can use this code snip, I use it every time I must loop through lots of rows.

Set AktCel_opt = AktSht.Range("R1")
Set NxtCel_opt = AktCel_opt.Offset(1, 0)

Do While Not IsEmpty(AktCel_opt)
Set NxtCel_opt = AktCel_opt.Offset(1, 0)

'************************************************
' Here is the code You wants to run for every row
' Could bee a new loop change the Q- cell until
' R- is zero
'*************************************************


Set AktCel_opt = NxtCel_opt
Loop


Thanks, makes sense. I found a code online and modified it. It worked but are there any pitfalls?

Public Sub GoalSeeker()


' Application.ScreenUpdating = False
' Application.Calculation = xlCalculationManual


With Sheets("Sheet1")


For I = 3 To .Cells(.Rows.Count, "R").End(xlUp).Row
.Cells(I, "R").GoalSeek Goal:=0, ChangingCell:=.Cells(I, "Q")
Next I


End With


' Application.ScreenUpdating = True
' Application.Calculation = xlCalculationAutomatic


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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