vba training london - formularc
Microsoft Office TrainingThe UK's Number 1 for Microsoft Office Training Sitemap add this page to your favourites/bookmarksBookmark page
 
view a printable version of this 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 training london - FormulaR1C1

vba training london - FormulaR1C1

resolvedResolved · Low Priority · Version Standard

replyReplyMon 2 Jul 2007, 09:59Delegate Martin said...

FormulaR1C1

I am trying to reference a named range in a formulaR1C1 but receive an error each time. the code is as follows:

Sub Percentages()

Dim Total As Range
Dim Counter As Integer
Dim Mycell As Range

Rows("2:2").Select
Selection.Insert Shift:=xlDown
Range("A2:F2").Select
Range("F2").Activate
Selection.Interior.ColorIndex = xlNone
Range("F2").Select


Set Total = ActiveCell
Set Mycell = ActiveCell.Offset(0, 1)

Counter = 2
Cells(Counter, 6).Activate

Do
If Cells(Counter, 6) = "" Then
Total = ActiveCell
ActiveCell.Offset(0, 1) = Mycell
Mycell.Activate

ActiveCell.FormulaR1C1 = "=sum(RC[-1]/"& Total &")"
Else
ActiveCell.Offset(0, 1) = Mycell
Mycell.Activate
ActiveCell.FormulaR1C1 = "=sum(RC[-1]/"& Total &")"
Cells(Counter, 6).Activate
Counter = Counter + 1
End If

Loop Until Cells(Counter, 6) = "end"


End Sub

The purpose of the formula is to calculate a percentage of a total that will go into the blank cell, and there will be lots of totals at irregular intervals.

Any help greatly appreciated.

Many thanks
Martin

For upcoming training course dates see: Pricing & availability

replyReplyTue 17 Jul 2007, 11:22Trainer Carlos said...

RE: FormulaR1C1

Martin

Sorry for the delay.

I looked at your code and tried to run it on a Worksheet I set up.

In my test the system is loading a blank value into the Total variable which when trying to do the Formula is triggering an error.

I went through it using F8 and by moving row 2 down you are looking at a blank "F2" cell qand loading its value into Total.

Apart from the above, I would need to see this working on the original workbook to see where else it is going wrong.

Carlos

replyReplyTue 17 Jul 2007, 11:25Trainer Carlos said...

RE: FormulaR1C1

Martin

If you want to send the document, email it to

forum AT microsofttraining.net

Carlos

replyReplyTue 17 Jul 2007, 15:13Trainer Carlos said...

RE: FormulaR1C1

Martin

Its as I said before. The way you have the code presently you are moving the data down One line and then loading the value of a blank cell into Total which means you are dividing by it in the equation.

Run the code through using F8 (Step through) and keep flicking back tgo the Spreadsheet and watch how the data behaves.

If the moving down of the data is required then you need to rewrite the code so that the computer picks the value from any other cell except "F2" or cells (Counter, 6).

Carlos

 

 

Vba tip:

Good coding practice

It is important that you always comment the VBA code that you write. By doing this it will make the code much easier to read, as both yourself and other people will be able to see what the code is doing or meant to be doing. This is very important if there is more than one person who writes code in the company as you may have different styles of coding and may not really understand what the other person is trying to do. Also if you write some code and then do not touch it for a year or so you may actually forget what it is meant to be doing. so it is very important to include comments throughout your code and try and make sure that they are as useful as possible

View all VBA hints and tips

forum postHow do Macro's work

» Forum post: Macros


Rate this page:
2.2/5 (213 votes cast)
Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses
Microsoft Certified Partner
Security Seal verified by visa, mastercard securecard

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

Management training

Professional Skills courses
Project Management Course London
Project Management Courses London
Project Management Training London
Project Management Training
Project Seminar
Project Seminars
Time Management Course London
Time Management London
Time Management Courses London
Time Management Training London
Introduction to Finance course
Assertiveness Skills course
Effective Communications Skills training
Presentation Skills London

Training Formats

Public scheduled courses
On-site training
Closed company courses

Consultancy
Application Development

Blogs

Excel Training
MS Project Training
Microsoft Training Blog

Version differences

Office 2010 vs 2007
MS Project version differences

Training Information

London Computer Training
Computer Training London
Docklands Training Courses
Docklands Training London

Training venues London
Client list
FAQ
Pricing and availability
Course details / Syllabus

Training Articles
Training Information

Microsoft training

Microsoft Office training
& IT Applications

Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training
MS Project courses
MS Project training
Outlook courses
PowerPoint courses
PowerPoint training
VBA courses
Word courses
Microsoft.training
(more...)

Excel Training

Excel courses
Excel Training Courses Medway
Autonumber in Excel
Microsoft Excel training
Basic Excel Courses
Basic Excel Course
Basic Excel Training

Interested in MS Access training?

Access courses
Microsoft Access training
Microsoft access courses
Microsoft training access course
Microsoft+access+training
Access courses in london

Training provider

Training providers
IT training companies
IT training providers
Management Training providers
Management Training provider

Event history, feedback results
Events in 2012 · 2011 · 2010 · More

See also

Crystal Reports training