VBA MAcro HELP

agus9

New Member
Joined
Nov 15, 2013
Messages
2
Hey guys. I need help for the following. I am SURE there is a faster code but I am new to coding and do not really know the commands for what I need to do. Below is the coding that I have now.

___________________________________________________________
Sub Solver()
'
' Solver Macro
'
'
Range("F20").Select
Range("F20").GoalSeek Goal:=0, ChangingCell:=Range("B7")
Range("F21").Select
Range("F21").GoalSeek Goal:=0, ChangingCell:=Range("G21")
Range("F22").Select
Range("F22").GoalSeek Goal:=0, ChangingCell:=Range("G22")
Range("F23").Select
Range("F23").GoalSeek Goal:=0, ChangingCell:=Range("G23")
Range("F24").Select
Range("F24").GoalSeek Goal:=0, ChangingCell:=Range("G24")
Range("F25").Select
Range("F25").GoalSeek Goal:=0, ChangingCell:=Range("G25")
End Sub

___________________________________________________________________

As you can see, I am using the same code over and over again, I'm just going one row down each time. I need to go all the way to 500 and dont want to copy and paste and change the row number. Someone Please HELP ME!

Thanks!!!:confused::mad:
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi,

Can you use looping?
Code:
    Dim R as long

    For R=25 to 500
        Range("F" & R).GoalSeek Goal:=0, ChangingCell:=Range("G" & R)
    Next R

To start with the last row in your example.

Succes,

Paul
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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