1

Every day i need to link today's opening balance to previous day's closing balance ,i have recorded a macro like this

    Range("D5").Select
ActiveCell.FormulaR1C1 = "='27.07.18'!RC[6]"
Range("D5").Select
Selection.AutoFill Destination:=Range("D5:E5"), Type:=xlFillDefault
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:E86"), Type:=xlFillDefault
Range("D5:E86").Select
Range("D82").Select

This does the work but every day i have to chance a file name to today's date (as date is my sheet name )

Can i Use a Variable Insted Of Sheet name in FormulaR1C1

1
  • 2
    Yes, you can :-) Commented Jul 30, 2018 at 11:36

2 Answers 2

3

Try

Dim s As String
s = Format$(DATE,"dd.mm.yy")
ActiveCell.FormulaR1C1 = "='" & s &"'!RC[6]"

Assumes that the sheet already exists with this name. Otherwise first you need

Sheets.Add
Activesheet.Name = s

And you need to have the ActiveCell actually reference the original cell as the newly added sheet would have shifted this.

*Note: If previous day please use s = Format$(DATE-1,"dd.mm.yy")

Sign up to request clarification or add additional context in comments.

2 Comments

... to previous day's closing balance.. I think OP wants the previous day, so s = Format$(DATE-1,"dd.mm.yy"), but I could be wrong. Anyways, your code is good :)
Oops! Thanks for that.
0

You could base it on a string var.

dim ws1 as string, ws2 as string

ws1 = "26.07.18"
ws2 = "27.07.18"

with worksheets(ws2)
    .Range("D5:E86").FormulaR1C1 = "='" & ws1 & "'!RC[6]"
end with

Perhaps you are adding a worksheet to the end of the queue every day.

with worksheets(worksheets.count)
    .Range("D5:E86").FormulaR1C1 = _
        "='" & worksheets(worksheets.count-1).name & "'!RC[6]"
end with

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.