jasonleewkd
New Member
Hi all, this must be a really easy question but I'm just getting started with VBA, and coding in general. I wrote a short macro to perform multiple goal seeks and the below is what I got. Now I'm sure the code can be shortened to a few lines by assigning some variables and looping, and I think the For loop can help, but I'm not sure how to get started. Would appreciate if anyone can show me a shorter version of the code below that'll help greatly in my learning!
Code:
Sub Goal_Seek()
Dim X As Double
X = 0
Sheets("Prime Total Returns").Select
Range("CA10").Select
Range("CA10").GoalSeek Goal:=X, ChangingCell:=Range("CC10")
Sheets("Prime Total Returns").Select
Range("CA11").Select
Range("CA11").GoalSeek Goal:=X, ChangingCell:=Range("CC11")
Sheets("Prime Total Returns").Select
Range("CA12").Select
Range("CA12").GoalSeek Goal:=X, ChangingCell:=Range("CC12")
Sheets("Prime Total Returns").Select
Range("CA13").Select
Range("CA13").GoalSeek Goal:=X, ChangingCell:=Range("CC13")
Sheets("Prime Total Returns").Select
Range("CA14").Select
Range("CA14").GoalSeek Goal:=X, ChangingCell:=Range("CC14")
Sheets("Prime Total Returns").Select
Range("CA16").Select
Range("CA16").GoalSeek Goal:=X, ChangingCell:=Range("CC16")
Sheets("Prime Total Returns").Select
Range("CA17").Select
Range("CA17").GoalSeek Goal:=X, ChangingCell:=Range("CC17")
Sheets("Prime Total Returns").Select
Range("CA18").Select
Range("CA18").GoalSeek Goal:=X, ChangingCell:=Range("CC18")
Sheets("Prime Total Returns").Select
Range("CA20").Select
Range("CA20").GoalSeek Goal:=X, ChangingCell:=Range("CC20")
Sheets("Prime Total Returns").Select
Range("CA21").Select
Range("CA21").GoalSeek Goal:=X, ChangingCell:=Range("CC21")
Sheets("Prime Total Returns").Select
Range("CA10").Select
End Sub
Last edited by a moderator: