How to Use VBA to Loop goal seek down columns
up vote
0
down vote
favorite
I am new to this site and brand new to VBA. I have a question related to goal seek.
I need to use Goal seek in VBA several times. Here is a sample of my Excel Sheet:

I need to set the cells in F(which is a formula linked to another sheet) to 0, by changing the cells in I (hardcoded). I have the basic code to do this, but I want to figure out how to tell Excel "hey, loop this action for every cell in the column". I don't want to have to manually put this command in VBA hundreds of times. Here is what I actually have in VBA.
Sub Goal_Seek()
'
' Goal_Seek Macro
Range("F7").Select
Range("F7").GoalSeek Goal:=0, ChangingCell:=Range("I7")
Range("F8").Select
Range("F8").GoalSeek Goal:=0, ChangingCell:=Range("I8")
Range("F9").Select
Range("F9").GoalSeek Goal:=0, ChangingCell:=Range("I9")
Range("F10").Select
Range("F10").GoalSeek Goal:=0, ChangingCell:=Range("I10")
Range("F11").Select
Range("F11").GoalSeek Goal:=0, ChangingCell:=Range("I11")
End Sub
Any help is appreciated.
excel vba
add a comment |
up vote
0
down vote
favorite
I am new to this site and brand new to VBA. I have a question related to goal seek.
I need to use Goal seek in VBA several times. Here is a sample of my Excel Sheet:

I need to set the cells in F(which is a formula linked to another sheet) to 0, by changing the cells in I (hardcoded). I have the basic code to do this, but I want to figure out how to tell Excel "hey, loop this action for every cell in the column". I don't want to have to manually put this command in VBA hundreds of times. Here is what I actually have in VBA.
Sub Goal_Seek()
'
' Goal_Seek Macro
Range("F7").Select
Range("F7").GoalSeek Goal:=0, ChangingCell:=Range("I7")
Range("F8").Select
Range("F8").GoalSeek Goal:=0, ChangingCell:=Range("I8")
Range("F9").Select
Range("F9").GoalSeek Goal:=0, ChangingCell:=Range("I9")
Range("F10").Select
Range("F10").GoalSeek Goal:=0, ChangingCell:=Range("I10")
Range("F11").Select
Range("F11").GoalSeek Goal:=0, ChangingCell:=Range("I11")
End Sub
Any help is appreciated.
excel vba
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am new to this site and brand new to VBA. I have a question related to goal seek.
I need to use Goal seek in VBA several times. Here is a sample of my Excel Sheet:

I need to set the cells in F(which is a formula linked to another sheet) to 0, by changing the cells in I (hardcoded). I have the basic code to do this, but I want to figure out how to tell Excel "hey, loop this action for every cell in the column". I don't want to have to manually put this command in VBA hundreds of times. Here is what I actually have in VBA.
Sub Goal_Seek()
'
' Goal_Seek Macro
Range("F7").Select
Range("F7").GoalSeek Goal:=0, ChangingCell:=Range("I7")
Range("F8").Select
Range("F8").GoalSeek Goal:=0, ChangingCell:=Range("I8")
Range("F9").Select
Range("F9").GoalSeek Goal:=0, ChangingCell:=Range("I9")
Range("F10").Select
Range("F10").GoalSeek Goal:=0, ChangingCell:=Range("I10")
Range("F11").Select
Range("F11").GoalSeek Goal:=0, ChangingCell:=Range("I11")
End Sub
Any help is appreciated.
excel vba
I am new to this site and brand new to VBA. I have a question related to goal seek.
I need to use Goal seek in VBA several times. Here is a sample of my Excel Sheet:

I need to set the cells in F(which is a formula linked to another sheet) to 0, by changing the cells in I (hardcoded). I have the basic code to do this, but I want to figure out how to tell Excel "hey, loop this action for every cell in the column". I don't want to have to manually put this command in VBA hundreds of times. Here is what I actually have in VBA.
Sub Goal_Seek()
'
' Goal_Seek Macro
Range("F7").Select
Range("F7").GoalSeek Goal:=0, ChangingCell:=Range("I7")
Range("F8").Select
Range("F8").GoalSeek Goal:=0, ChangingCell:=Range("I8")
Range("F9").Select
Range("F9").GoalSeek Goal:=0, ChangingCell:=Range("I9")
Range("F10").Select
Range("F10").GoalSeek Goal:=0, ChangingCell:=Range("I10")
Range("F11").Select
Range("F11").GoalSeek Goal:=0, ChangingCell:=Range("I11")
End Sub
Any help is appreciated.
excel vba
excel vba
edited Nov 21 at 18:21
BigBen
4,7752417
4,7752417
asked Nov 21 at 18:14
austinmb
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Maybe something like:
Sub Goal_Seek()
Dim lastRow As Long, i As Long
With ActiveSheet
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = 7 To lastRow
.Range("F" & i).GoalSeek Goal:=0, ChangingCell:=.Range("I" & i)
Next i
End With
End Sub
Are you saying to put this before the set of commands that I have?
– austinmb
Nov 21 at 18:34
No - this should be it. TheForloop does what you want.
– BigBen
Nov 21 at 18:36
Can you point me to somewhere where I can learn about the syntax?— for ex: what’s “as long” and what’s .end(xlup).row? Finally “For... next” thanks!
– austinmb
Nov 21 at 19:05
Maybe here
– BigBen
Nov 21 at 19:07
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Maybe something like:
Sub Goal_Seek()
Dim lastRow As Long, i As Long
With ActiveSheet
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = 7 To lastRow
.Range("F" & i).GoalSeek Goal:=0, ChangingCell:=.Range("I" & i)
Next i
End With
End Sub
Are you saying to put this before the set of commands that I have?
– austinmb
Nov 21 at 18:34
No - this should be it. TheForloop does what you want.
– BigBen
Nov 21 at 18:36
Can you point me to somewhere where I can learn about the syntax?— for ex: what’s “as long” and what’s .end(xlup).row? Finally “For... next” thanks!
– austinmb
Nov 21 at 19:05
Maybe here
– BigBen
Nov 21 at 19:07
add a comment |
up vote
0
down vote
Maybe something like:
Sub Goal_Seek()
Dim lastRow As Long, i As Long
With ActiveSheet
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = 7 To lastRow
.Range("F" & i).GoalSeek Goal:=0, ChangingCell:=.Range("I" & i)
Next i
End With
End Sub
Are you saying to put this before the set of commands that I have?
– austinmb
Nov 21 at 18:34
No - this should be it. TheForloop does what you want.
– BigBen
Nov 21 at 18:36
Can you point me to somewhere where I can learn about the syntax?— for ex: what’s “as long” and what’s .end(xlup).row? Finally “For... next” thanks!
– austinmb
Nov 21 at 19:05
Maybe here
– BigBen
Nov 21 at 19:07
add a comment |
up vote
0
down vote
up vote
0
down vote
Maybe something like:
Sub Goal_Seek()
Dim lastRow As Long, i As Long
With ActiveSheet
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = 7 To lastRow
.Range("F" & i).GoalSeek Goal:=0, ChangingCell:=.Range("I" & i)
Next i
End With
End Sub
Maybe something like:
Sub Goal_Seek()
Dim lastRow As Long, i As Long
With ActiveSheet
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = 7 To lastRow
.Range("F" & i).GoalSeek Goal:=0, ChangingCell:=.Range("I" & i)
Next i
End With
End Sub
answered Nov 21 at 18:31
BigBen
4,7752417
4,7752417
Are you saying to put this before the set of commands that I have?
– austinmb
Nov 21 at 18:34
No - this should be it. TheForloop does what you want.
– BigBen
Nov 21 at 18:36
Can you point me to somewhere where I can learn about the syntax?— for ex: what’s “as long” and what’s .end(xlup).row? Finally “For... next” thanks!
– austinmb
Nov 21 at 19:05
Maybe here
– BigBen
Nov 21 at 19:07
add a comment |
Are you saying to put this before the set of commands that I have?
– austinmb
Nov 21 at 18:34
No - this should be it. TheForloop does what you want.
– BigBen
Nov 21 at 18:36
Can you point me to somewhere where I can learn about the syntax?— for ex: what’s “as long” and what’s .end(xlup).row? Finally “For... next” thanks!
– austinmb
Nov 21 at 19:05
Maybe here
– BigBen
Nov 21 at 19:07
Are you saying to put this before the set of commands that I have?
– austinmb
Nov 21 at 18:34
Are you saying to put this before the set of commands that I have?
– austinmb
Nov 21 at 18:34
No - this should be it. The
For loop does what you want.– BigBen
Nov 21 at 18:36
No - this should be it. The
For loop does what you want.– BigBen
Nov 21 at 18:36
Can you point me to somewhere where I can learn about the syntax?— for ex: what’s “as long” and what’s .end(xlup).row? Finally “For... next” thanks!
– austinmb
Nov 21 at 19:05
Can you point me to somewhere where I can learn about the syntax?— for ex: what’s “as long” and what’s .end(xlup).row? Finally “For... next” thanks!
– austinmb
Nov 21 at 19:05
Maybe here
– BigBen
Nov 21 at 19:07
Maybe here
– BigBen
Nov 21 at 19:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418253%2fhow-to-use-vba-to-loop-goal-seek-down-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown