Changing formula in cell using for loop index numbers as cell ref

Dax4201

New Member
Joined
Mar 31, 2011
Messages
2
I can't find anything that seems address my problem. I am trying to build formulas in a sheet referencing cells in other sheets in a workbook. I won't know the number of sheets in the workbook until run-time. As I am building those sheets based the number of sheet in a separate workbook.

I am having trouble selecting the cell to put the formula into. Range uses "A1" reference, but I need to use the indexes from my For loops to reference the cell.

As in the code below. Any suggestions would be greatly appreciated.

Code:
Private Sub create_Dist_Sheet()
Dim i As Integer
Dim j As Integer
Dim tempPath As String

    'template sheet 
    tempPath = "C:\Documents and Settings...."
    Set newSheet = newBook.Sheets.Add(Type:=tempPath)
    
    For i = 4 To 26 Step 2
        For j = 3 To 65
            
            With newSheet
               .Cells(j, i).FormulaR1C1 = "=SUM(" & newBook.Sheet(2).Name & ":" & _
                newBook.Sheets(newBook.Sheets.Count).Name & "!" & Chr(i + 64) & ")"
            End With
        Next j
          
     Next i
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,224,574
Messages
6,179,629
Members
452,933
Latest member
patv

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