Announcement

Collapse
No announcement yet.

Macro Loop

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Macro Loop



    Hi,

    I am currently using a macro, where I extend the range by repeating the calcs. I was hoping if someone can suggest the format for repeating for a certain no. of times.

    Code

    Code:
    Sub Macro1()
    
    Range("F67").GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G67")
    Range("F68").GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G68")
    Range("F69").GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G69")
    Range("F70").GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G70")
    Range("F71").GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G71")
    Range("F72").GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G72")
    Range("F73").GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G73")
    Range("F74").GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G74")
    
    
    End Sub

  • #2
    Alan Code Tags
    Code Tags Added
    Your post does not comply with our Forum RULES. Use code tags around code.

    Posting code between tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window.

    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan

    Did you debug your code first? http://www.cpearson.com/excel/DebuggingVBA.aspx
    FORUM RULES----->http://www.ozgrid.com/forum/announcement.php?f=8

    If someone has helped you, say "thank you" by clicking on the Like Button.

    Comment


    • #3
      Maybe
      Code:
      Option Explicit
      
      Sub Macro1()
          Dim i As Long
          For i = 67 To 74
              Range("F" & i).GoalSeek Goal:=Worksheets("S1").Range("B14").Value, ChangingCell:=Range("G" & i)
          Next i
      End Sub
      Alan

      Did you debug your code first? http://www.cpearson.com/excel/DebuggingVBA.aspx
      FORUM RULES----->http://www.ozgrid.com/forum/announcement.php?f=8

      If someone has helped you, say "thank you" by clicking on the Like Button.

      Comment


      • #4


        Hi Alan,

        Thanks. Yes. This is exactly what I wanted.

        Best Wishes

        Comment

        Working...
        X