title: Can this Macro be changed to work for any variable number of funds?
body: <p>This macro was written long before I was in my current role but now I want to improve it and make it work for any x number of funds. I am pasting just the part of the macro up to 4 funds but it continues the same way for up to 50 funds right now which you can imagine what a nightmare that is.</p>
  <p>Edit: I should have mentioned, I intend to go through and remove all the Select and Activate commands where possible. This was done by someone on the Macro Recorder a few years ago so that is definitely a part of my clean-up but figuring out how to have the number of sheets copied and have the formulas work for any number of funds is what I am struggling with.</p>
  <pre><code>Sub MultiFunds()
  
  MultiFund = InputBox(&quot;Enter the Total number of Funds. Up to 50.&quot;, &quot;Up to Fifty Funds can be added on this form.&quot;)
  
  
  ' Copying Sheet
  ActiveSheet.Unprotect
      Sheets(&quot;Fund 1&quot;).Copy Before:=Sheets(6)
      Sheets(&quot;Fund 1 (2)&quot;).Name = &quot;Fund 2&quot;
      
  'Linking Cells Directs and IDC
      Sheets(&quot;Cumulative&quot;).Select
      Range(&quot;F15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
      Range(&quot;F17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
      Range(&quot;F15&quot;).AutoFill Destination:=Range(&quot;F15:K15&quot;), Type:=xlFillDefault
      Range(&quot;F17&quot;).AutoFill Destination:=Range(&quot;F17:K17&quot;), Type:=xlFillDefault
      
      Range(&quot;M15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
      Range(&quot;M17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
      Range(&quot;N15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
      Range(&quot;N17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
  
      
   'Linking Exclusions
      Range(&quot;F29&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
      Range(&quot;F29&quot;).AutoFill Destination:=Range(&quot;F29:K29&quot;), Type:=xlFillDefault
      Range(&quot;F29:K29&quot;).AutoFill Destination:=Range(&quot;F29:k36&quot;), Type:=xlFillDefault
      Range(&quot;M29&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
      Selection.AutoFill Destination:=Range(&quot;M29:m36&quot;), Type:=xlFillDefault
      Range(&quot;N29&quot;).Select
      ActiveCell.FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC&quot;
      Selection.AutoFill Destination:=Range(&quot;N29:n36&quot;), Type:=xlFillDefault
      
      'Linking Dates
      Sheets(&quot;Fund 1&quot;).Select
      Range(&quot;F11&quot;).FormulaR1C1 = &quot;=+Cumulative!RC&quot;
      Range(&quot;F12&quot;).FormulaR1C1 = &quot;=+Cumulative!RC&quot;
      Range(&quot;F11&quot;).AutoFill Destination:=Range(&quot;F11:K11&quot;), Type:=xlFillDefault
      Range(&quot;F12&quot;).AutoFill Destination:=Range(&quot;F12:K12&quot;), Type:=xlFillDefault
      Range(&quot;F13&quot;).FormulaR1C1 = &quot;=+Cumulative!RC&quot;
      Range(&quot;F13&quot;).AutoFill Destination:=Range(&quot;F13:K13&quot;), Type:=xlFillDefault
      Range(&quot;M13&quot;).FormulaR1C1 = &quot;=+Cumulative!RC&quot;
      Range(&quot;N13&quot;).FormulaR1C1 = &quot;=+Cumulative!RC&quot;
  
  
    
      ActiveCell.FormulaR1C1 = &quot;=+Cumulative!RC&quot;
      Range(&quot;C5&quot;).FormulaR1C1 = &quot;=+Cumulative!RC&quot;
      
      Sheets(&quot;Fund 1&quot;).Select
      Range(&quot;C3&quot;).FormulaR1C1 = &quot;=+Cumulative!RC&quot;
      Range(&quot;C5&quot;).FormulaR1C1 = &quot;=+Cumulative!RC&quot;
  
      
     ' Linkin Summary Sheet
      
      Sheets(&quot;Summary&quot;).Select
      ActiveSheet.Unprotect
      Range(&quot;A4&quot;).FormulaR1C1 = &quot;=+'Fund 1'!R[-2]C[2]&quot;
      Range(&quot;B4&quot;).FormulaR1C1 = &quot;=+'Fund 1'!R[22]C[1]&quot;
      Range(&quot;C4&quot;).FormulaR1C1 = &quot;=+'Fund 1'!R[15]C[9]&quot;
      Range(&quot;D4&quot;).FormulaR1C1 = &quot;=+'Fund 1'!R[15]C[9]+'Fund 1'!R[15]C[10]&quot;
      Range(&quot;E4&quot;).FormulaR1C1 = &quot;=+RC[-2]+RC[-1]&quot;
      Range(&quot;F4&quot;).FormulaR1C1 = &quot;=+'Fund 1'!R[24]C[-3]&quot;
      Range(&quot;G4&quot;).FormulaR1C1 = &quot;=+RC[-5]-RC[-2]-RC[-1]&quot;
      
      Range(&quot;A5&quot;).FormulaR1C1 = &quot;=+'Fund 2'!R[-3]C[2]&quot;
      Range(&quot;B5&quot;).FormulaR1C1 = &quot;=+'Fund 2'!R[21]C[1]&quot;
      Range(&quot;C5&quot;).FormulaR1C1 = &quot;=+'Fund 2'!R[14]C[9]&quot;
      Range(&quot;D5&quot;).FormulaR1C1 = &quot;=+'Fund 2'!R[14]C[9]+'Fund 2'!R[14]C[10]&quot;
      Range(&quot;E5&quot;).FormulaR1C1 = &quot;=+RC[-2]+RC[-1]&quot;
      Range(&quot;F5&quot;).FormulaR1C1 = &quot;=+'Fund 2'!R[23]C[-3]&quot;
      Range(&quot;G5&quot;).FormulaR1C1 = &quot;=+RC[-5]-RC[-2]-RC[-1]&quot;
      
      'Hide Rows
       Rows(&quot;6:33&quot;).EntireRow.Hidden = True
       
       Sheets(&quot;Summary&quot;).Select
       ActiveSheet.Protect
       Sheets(&quot;Cumulative&quot;).Select
       ActiveSheet.Protect
       Sheets(&quot;Fund 1&quot;).Select
       ActiveSheet.Protect
       Sheets(&quot;Fund 2&quot;).Select
       ActiveSheet.Protect
       
  If MultiFund = 2 Then
  End If
  
      If MultiFund = 3 Then
  
      Sheets(&quot;Cumulative&quot;).Select
      ActiveSheet.Unprotect
      Sheets(&quot;Fund 1&quot;).Copy Before:=Sheets(7)
      Sheets(&quot;Fund 1 (2)&quot;).Name = &quot;Fund 3&quot;
      
  'LINKING DIRECT And INDIRECTs
  
      Sheets(&quot;Cumulative&quot;).Select
      Range(&quot;F15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      Range(&quot;F17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      Range(&quot;F15&quot;).AutoFill Destination:=Range(&quot;F15:K15&quot;), Type:=xlFillDefault
      Range(&quot;F17&quot;).AutoFill Destination:=Range(&quot;F17:K17&quot;), Type:=xlFillDefault
      Range(&quot;M15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      Range(&quot;M17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      Range(&quot;N15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      Range(&quot;N17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      
  'LINKING EXCLUSIONS
  
      Range(&quot;F29&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      Range(&quot;F29&quot;).AutoFill Destination:=Range(&quot;F29:K29&quot;), Type:=xlFillDefault
      Range(&quot;F29:K29&quot;).AutoFill Destination:=Range(&quot;F29:k36&quot;), Type:=xlFillDefault
      Range(&quot;M29&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      Selection.AutoFill Destination:=Range(&quot;M29:m36&quot;), Type:=xlFillDefault
      Range(&quot;N29&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC&quot;
      Selection.AutoFill Destination:=Range(&quot;N29:n36&quot;), Type:=xlFillDefault
      
     
      'Linking Summary sheet
    
      
      Sheets(&quot;Summary&quot;).Select
      ActiveSheet.Unprotect
      Rows(&quot;6&quot;).EntireRow.Hidden = False
      
      Range(&quot;A6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[-4]C[2]&quot;
      Range(&quot;B6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[20]C[1]&quot;
      Range(&quot;C6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[13]C[9]&quot;
      Range(&quot;D6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[13]C[9]+'Fund 3'!R[13]C[10]&quot;
      Range(&quot;E6&quot;).FormulaR1C1 = &quot;=+RC[-2]+RC[-1]&quot;
      Range(&quot;F6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[22]C[-3]&quot;
      Range(&quot;G6&quot;).FormulaR1C1 = &quot;=+RC[-5]-RC[-2]-RC[-1]&quot;
      
       Sheets(&quot;Summary&quot;).Protect
       Sheets(&quot;Cumulative&quot;).Protect
       Sheets(&quot;Fund 1&quot;).Protect
       Sheets(&quot;Fund 2&quot;).Protect
       Sheets(&quot;Fund 3&quot;).Protect
  
  End If
  
  If MultiFund = 4 Then
  
      Sheets(&quot;Cumulative&quot;).Unprotect
      
      Sheets(&quot;Fund 1&quot;).Copy Before:=Sheets(7)
      Sheets(&quot;Fund 1 (2)&quot;).Name = &quot;Fund 3&quot;
      Sheets(&quot;Fund 1&quot;).Copy Before:=Sheets(8)
      Sheets(&quot;Fund 1 (2)&quot;).Name = &quot;Fund 4&quot;
  
  'LINKING DIRECT And INDIRECTs
  
      Sheets(&quot;Cumulative&quot;).Select
      Range(&quot;F15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      Range(&quot;F17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      Range(&quot;F15&quot;).AutoFill Destination:=Range(&quot;F15:K15&quot;), Type:=xlFillDefault
      Range(&quot;F17&quot;).AutoFill Destination:=Range(&quot;F17:K17&quot;), Type:=xlFillDefault
      Range(&quot;M15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      Range(&quot;M17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      Range(&quot;N15&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      Range(&quot;N17&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      
  'LINKING EXCLUSIONS
  
      Range(&quot;F29&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      Range(&quot;F29&quot;).AutoFill Destination:=Range(&quot;F29:K29&quot;), Type:=xlFillDefault
      Range(&quot;F29:K29&quot;).AutoFill Destination:=Range(&quot;F29:K36&quot;), Type:=xlFillDefault
      Range(&quot;M29&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      Selection.AutoFill Destination:=Range(&quot;M29:m36&quot;), Type:=xlFillDefault
      Range(&quot;N29&quot;).FormulaR1C1 = &quot;=+'Fund 1'!RC+'Fund 2'!RC+'Fund 3'!RC+'Fund 4'!RC&quot;
      Selection.AutoFill Destination:=Range(&quot;N29:n36&quot;), Type:=xlFillDefault
        
   'Linking Summary Sheet
   
      Sheets(&quot;Summary&quot;).Unprotect
      Rows(&quot;6:7&quot;).EntireRow.Hidden = False
   
      
      Range(&quot;A6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[-4]C[2]&quot;
      Range(&quot;B6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[20]C[1]&quot;
      Range(&quot;C6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[13]C[9]&quot;
      Range(&quot;D6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[13]C[9]+'Fund 3'!R[13]C[10]&quot;
      Range(&quot;E6&quot;).FormulaR1C1 = &quot;=+RC[-2]+RC[-1]&quot;
      Range(&quot;F6&quot;).FormulaR1C1 = &quot;=+'Fund 3'!R[22]C[-3]&quot;
      Range(&quot;G6&quot;).FormulaR1C1 = &quot;=+RC[-5]-RC[-2]-RC[-1]&quot;
      
      Range(&quot;A7&quot;).FormulaR1C1 = &quot;=+'Fund 4'!R[-5]C[2]&quot;
      Range(&quot;B7&quot;).FormulaR1C1 = &quot;=+'Fund 4'!R[19]C[1]&quot;
      Range(&quot;C7&quot;).FormulaR1C1 = &quot;=+'Fund 4'!R[12]C[9]&quot;
      Range(&quot;D7&quot;).FormulaR1C1 = &quot;=+'Fund 4'!R[12]C[9]+'Fund 4'!R[12]C[10]&quot;
      Range(&quot;E7&quot;).FormulaR1C1 = &quot;=+RC[-2]+RC[-1]&quot;
      Range(&quot;F7&quot;).FormulaR1C1 = &quot;=+'Fund 4'!R[21]C[-3]&quot;
      Range(&quot;G7&quot;).FormulaR1C1 = &quot;=+RC[-5]-RC[-2]-RC[-1]&quot;
    
       Sheets(&quot;Summary&quot;).Protect
       Sheets(&quot;Cumulative&quot;).Protect
       Sheets(&quot;Fund 1&quot;).Protect
       Sheets(&quot;Fund 2&quot;).Protect
       Sheets(&quot;Fund 3&quot;).Protect
       Sheets(&quot;Fund 4&quot;).Protect
  
  End If
  End Sub
  </code></pre>
  <p>Any advice on how to change the code to create x number of copies as needed would be greatly appreciated!</p>