Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 24th, 2004, 08:27 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XL/VBA:Why do I get this error(Range.FormulaR1C1)?

I use this code to put a formula in a range of cells. If I run the code, I get the VBA-error "1004 Application-defined or object-defined error". If I then place the same formula in a cell on a worksheet in Excel, the calculations are done as expected. Why can't I place the formula from VBA?

Code:
shtMenu.Range(Cells(iMenuMinRow, iTblBaseColumn + 5), Cells(iMenuMaxRow, iTblBaseColumn + 5)).FormulaR1C1 = _
      "=SUMPRODUCT((Brongegevens!R2C1:R65536C1=RC[-4])*(Brongegevens!R2C5:R65536C5=RC[-2]);Brongegevens!R2C14:R65536C14)"
 
Old December 29th, 2004, 10:06 AM
Authorized User
 
Join Date: Oct 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shattered Send a message via Yahoo to shattered
Default

excel is looking for a standard cell reference rather than the R1C1 reference style. Excel will understand the notation but vba won't.


 
Old January 3rd, 2005, 04:51 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You first say that Excel will require a standard reference (A1). In the second sentence you say that it is VBA that will not understand the R1C1-notation and Excel will. Isn't that contradictory?
Thank you for your reply anyway!

 
Old January 3rd, 2005, 08:27 AM
Authorized User
 
Join Date: Jan 2005
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have changed your code as follows and it seems it's working!

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
ActiveSheet.Range(Cells(Target.Row, Target.Column + 5), Cells(Target.Row, Target.Column + 5)).FormulaR1C1 = _
      "=SUMPRODUCT((Brongegevens!R2C1:R65536C1=RC[-4])*(Brongegevens!R2C5:R65536C5=RC[-2]),Brongegevens!R2C14:R65536C14)"


End Sub

NOTE: the semi-collon(;) is replaced with coma (,)








Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Data from xl to database show error. venkateswararaochaganti ASP.NET 2.0 Basics 0 November 3rd, 2008 04:37 AM
VBA Macro FIND THIS MONTH in a given range mvatoi Excel VBA 3 August 24th, 2007 08:12 AM
XL VBA Compile - what occurs - why crash PCWeaver Excel VBA 0 September 13th, 2006 11:13 AM
Copying Xl sheet from one Xl file to another kesavan Excel VBA 1 July 3rd, 2006 10:11 PM
Method Range - VBA - Excel teatimer Beginning VB 6 0 May 22nd, 2006 03:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.