Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba courses london - referencing worksheets formula u

Forum home » Delegate support and help forum » Microsoft VBA Training and help » vba courses london - Referencing Worksheets in a formula using R1C1

vba courses london - Referencing Worksheets in a formula using R1C1

ResolvedVersion Standard

Martin has attended:
Excel VBA Intro Intermediate course

Referencing Worksheets in a formula using R1C1

I am trying to insert a formula using a loop that refers to a number of worksheets, but cannot get a variable to work using FormulaR1C1. The code is as follows:

Sub SummarysheetSalesVariances()

Dim LastRow As Integer
Dim StartSheet As Integer
Dim NextCell As Integer

LastRow = Range("a65536").End(xlUp).Row

StartSheet = 6
NextCell = 9

Do While StartSheet < LastRow + 1
Sheets("Summary").Select
Range("b" & NextCell).Select
ActiveCell.FormulaR1C1 = "=worksheets(6)!r[46]c"

StartSheet = StartSheet + 1

NextCell = NextCell + 1

Loop

End Sub

any help appreciated.
Thanks
Martin

Edited on Fri 26 Jan 2007, 11:28

RE: Referencing Worksheets in a formula using R1C1

R1C1 doesn't accept the use of Letters for columns

ActiveCell.FormulaR1C1 = only works by setting the range that counts the diffrence between the top and bottom of the range

eg ActiveCell.FormulaR1C1 = "=SUM(R[-42]C:R[-1]C)"

which means add up the range from the cell 42 rows away to the cell just above

When adding up a column of numbers whose length keeps changing it is always better to:

Create a variable

Select the respective sheet

Create a loop that goes down the list adding each new number to the variable

When the loop is completed move down to the next empty cell and paste the value in the variable

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

VBA tip:

Stop Display Alerts In Excel

When creating or deleting a Worksheet in Excel you don't want Excel to inform you "A file already exists....." Or "Do you want to save this file...".

To stop these alerts happening use the following line of code:

Application.DisplayAlerts = False

After the Create or Delete routine use:

Application.DisplayAlerts = True

View all VBA hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.