vba courses london - referencing worksheets formula u
Microsoft Office Training verified by visa - mastercard securecode about microsoft training company london ukadd this page to your favourites/bookmarksAdd to favourites
view a printable version of this pagePrintable version
email this page to somebodyEmail this page
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

The UK's most regular instructor-led training courses.
Training information: vba courses london · Excel london

resolvedResolved · Low Priority · Version Standard

Referencing Worksheets in a formula using R1C1

Martin has attended:
Excel VBA course

by - delegate Martin [4 posts] (2007 Jan 21 Sun, 15:05) replyReply

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

RE: Referencing Worksheets in a formula using R1C1

by - trainer Carlos gold contributer[479 posts] (2007 Jan 26 Fri, 11:26) Edited on 2007 Jan 26 Fri, 11:28 replyReply

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


Related articles

· How To Find A Good VB For Access Trainer
· What Is Microsoft Excel VBA and How Can It Help You Work Smarter?
· Should You Send Managers To VBA Training?
· Introduction to Visual Basic for Applications
· Visual Basic Returns To The Macintosh

Vba tip:

Count the Rows and Columns in a Selection

If you need to count the number of rows or columns in a worksheet use the following code:

Selection.Rows.Count - Returns the number of rows in the selection

Selection.Columns.Count - Returns the number of columns in the selection

Selection.CurrentRegion.Rows.Count - Returns the number of rows in the current region of the selection

View all VBA hints and tips

Rate this page:
4.0/5 (3 votes cast)
Institute of IT Training - Accredited Training Provider Microsoft Certified Partner
microsoft office
Microsoft Office Specialist Authorised Testing Centre (MOS and MCAS)

Prodigy Platinum Learning Partner

Institute of IT Training - Accredited Training Provider Association of Computer Trainers Valid HTML 4.01 Transitional
Valid CSS Markup

secure online payments - visa - mastercard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Training by application Main information pages See also

Access courses
DreamWeaver courses
Excel courses
MS Project courses
Outlook courses
PowerPoint courses
VBA courses
Word courses
(more...)

Public scheduled courses
On-site training
Closed company courses

Microsoft Office training
Pricing and availability
Training schedule
Training venues

Access training
Dreamweaver training
Excel training
MS Project training
PowerPoint training

London Computer Training
Computer Training London

Microsoft Access training
Microsoft Excel training
Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training

Time Management Course London

Interested in Access training? Please see the following pages:
microsoft access courses · microsoft training access course
microsoft+access+training · access courses in london

Training Information

Training Articles

AddThis Social Bookmark Button What's this?
Add to Del.icio.us Add to Facebook Add to Digg Add to Reddit Add to Google Add to Yahoo Add to Diigo Add to Mr. Wong Add to Linkarena Add to Power Oldie Add to Folkd Add to Jumptags Add to Upchuckr Add to Simpy Add to StumbleUpon Add to Slashdot Add to Netscape Add to Furl Add to Spurl Add to Blinklist Add to Blogmarks Add to Technorati Add to Newsvine Add to Blinkbits Add to Ma.Gnolia Add to Smarking Add to Netvouz