Is this macro easy to write?

excelos

Well-known Member
Joined
Sep 25, 2011
Messages
592
Office Version
  1. 365
Platform
  1. Windows
Hello!

Is it easy to write a macro that will fill a specific input cell with 0, 1, 2, 3, etc until the output cell becomes 0 (various formulas connect these two cells)

Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Have you used Goal Seek before? Data > What if Analysis > Goal Seek. Sounds like what you need, or if it must be a macro this is what a recorded Goal Seek looks like:

Code:
Range("B1").GoalSeek Goal:=10, ChangingCell:=Range("A1")

B1 had formula =A1*5
 
Upvote 0
Have you used Goal Seek before? Data > What if Analysis > Goal Seek. Sounds like what you need, or if it must be a macro this is what a recorded Goal Seek looks like:

Code:
Range("B1").GoalSeek Goal:=10, ChangingCell:=Range("A1")

B1 had formula =A1*5

Many thanks that is a great feature!
But the problem is that it does not allow me to specify criteria for the input cell.
Is that possible?
 
Upvote 0
Heres a loop that will increment B1 by 1 until A1 equals 0. You can change the number of iterations if you want. Dont know if thats what you mean.

Code:
a = 0
Do Until Range("A1").Value = 0
    Range("B1").Value = a
    If a = 5000 Then 'max number of iterations to prevent infinite loop
        Range("B1").Value = ""
        MsgBox "Max iterations reached. Cant find the result"
        Exit Sub
    End If
    a = a + 1
Loop
 
Upvote 0
Could you stop posting essentially the same question repeatedly, please.
 
Upvote 0
Have you used Goal Seek before? Data > What if Analysis > Goal Seek. Sounds like what you need, or if it must be a macro this is what a recorded Goal Seek looks like:

Code:
Range("B1").GoalSeek Goal:=10, ChangingCell:=Range("A1")

B1 had formula =A1*5

That is great! Do you know how to specify additional criteria for A1?
 
Upvote 0
Depends what you want to do. Goal seek just finds a number needed to solve an equation where the answer is known.

You could use goalseek only IF criteria is met.

Code:
If Range("A1") = 'some scenarios' then
'goalseek code
End if
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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