vba courses london - referencing worksheets formula u
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

resolvedResolved · Low Priority · Version Standard

replyReply Sun 21 Jan 2007, 15:05Delegate Martin said...

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

For upcoming training course dates see: Pricing & availability

replyReply Fri 26 Jan 2007, 11:26 Edited on Fri 26 Jan 2007, 11:28Trainer Carlos said...

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

 

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


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard