Sub CorrectYTDCalc()
	Dim FirstName As String, ReplaceName As String
	Dim N As Integer

	FirstName=Worksheets(1).Name
	FirstName=FirstName & "!"

	For N = 3 to Worksheets.Count
		Worksheets(N).Activate
		ReplaceName=Worksheets(N-1).Name
		ReplaceName=ReplaceName & "!"
		Range("A1", Range("A1").SpecialCells(xlLastCell)).Select
Selection.Replace what:=FirstName, replacement:=ReplaceName
	Next N
End Sub

Function YTD(CellRef) As Double
    Dim rw As Integer, cl As Integer, idx As Integer
    rw = CellRef.Row
    cl = CellRef.Column
    For idx = 1 To ActiveSheet.Index
        YTD = YTD + Worksheets(idx).Cells(rw, cl).Value
    Next
End Function

Sub BuildFormula()
    Dim CellRef As Range
    Dim Address As String
    
    Set CellRef = Application.InputBox(prompt:= _
        "Click on a cell or type the reference", _
        Title:="Which cell do you want in the sum?", _
        Type:=8)
    Address = CellRef.Address
    ActiveCell.Formula = _
  "=SUM(Jan:" & ActiveSheet.Name & "!" & Address & ")"
End Sub
