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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

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