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 forum

vba courses london - Referencing Worksheets in a formula using R1C1 | VBA forum

resolvedResolved · Low Priority · Version 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.


Server loaded in 0.05 secs.