Relative reference to sheet cells

N Prakash

Active Member
Joined
Nov 7, 2003
Messages
405
Hi,

I have about 100 sheets and I want to enter a start date in the Fourth sheet in cell B1. If I enter a formulae (eg. =Sheet4!B1+1) in fifth sheet by grouping all other sheets it should have a relative reference to the previous sheet and add one day in the subsequent sheet. Is it possible with formulae.

Any help please.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

galileogali

Well-known Member
Joined
Oct 14, 2005
Messages
748
You can to use

Code:
Sub formulaLoadI()

For Each SH In ThisWorkbook.Worksheets
If SH.CodeName <> "Sheet1" Then
SH.Range("B1").Formula = "=Sheet" & (Replace(SH.CodeName, "Sheet", "") - 1) & "!RC+1"
End If

Next SH

End Sub
or

Code:
Sub formulaLoadII()

For Each SH In ThisWorkbook.Worksheets
If SH.Name <> "Sheet1" Then
SH.Range("B1").Formula = "=Sheet" & (Replace(SH.Name, "Sheet", "") - 1) & "!RC+1"
End If

Next SH

End Sub

Galileogali
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

You could use a user defined function
Code:
Function prevsheetvalue()
    With Application.Caller
    prevsheetvalue = .Parent.Previous.Range(.Address).Value + 1
    End With
End Function

example:
sheet1 A3: "123"
sheet2 A3: = prevsheetvalue()
result "124"

kind regards,
Erik

EDIT:
some errorhandling in case you use this on first sheet (which would produce an error)
Code:
Function prevsheetvalue()

    With Application.Caller
        If .Parent.Index = 1 Then
        prevsheetvalue = "error"
        Else
        prevsheetvalue = .Parent.Previous.Range(.Address).Value + 1
        End If
    End With

End Function
 

N Prakash

Active Member
Joined
Nov 7, 2003
Messages
405
Hi,

Thank you very much for all the help. User defined function prevsheetvalue() is great.

Regards,
Prakash
 

Forum statistics

Threads
1,181,055
Messages
5,927,862
Members
436,573
Latest member
CMR237

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
Top