Macro to perform Goal Seek for many columns

Matt_86

New Member
Joined
Apr 7, 2011
Messages
3
Hi,

I need to perform goalseek to set the cells in row 61 (from column G onwards) to zero by changing the cells in row 40 (column G onward)

I can record a macro to do this for only 3 columns (as in my spreadsheet) but the problem is I will have approx 100 columns worth of different data and I need to perform the same Goal Seek function for each different column.

In other words I want to perform the following action:

Range("G61").goalseek Goal:=0, ChangingCell:=Range("G40")
End Sub

Except I need to do so for the subsequent columns H, I, J, K, L etc etc and I'm not sure how to amend the macro to do this(?)

Any help = greatly appreciated
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Someone please help..anyone.....surely it can't be that complex a problem but it is beyond my ultra-basic VBA capability
 
Upvote 0
Something like this?

Code:
Sub Gseek()
Dim LC As Long, j As Long
LC = Cells(1, Columns.Count).End(xlToLeft).Column
For j = 7 To LC
    Cells(61, j).GoalSeek Goal:=0, ChangingCell:=Cells(40, j)
Next j
End Sub
 
Upvote 0
VoG you champion.
The initial code below didn't work for some reason but I just removed the LC reference and set j = 7 To 100 (to perform 100 columns' worth of Goal Seeks).
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,580
Members
448,972
Latest member
Shantanu2024

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