+ Reply to Thread
Results 1 to 2 of 2

Using VBA to enter a SumProduct formula into a cell

Hybrid View

  1. #1
    Registered User
    Join Date
    07-10-2008
    Location
    Norwich, England
    MS-Off Ver
    Office XP
    Posts
    15

    Arrow Using VBA to enter a SumProduct formula into a cell

    I need to use VBA to build a SumProduct formula and enter it into various cells in my worksheet. This is what I have done so far:

    Range("E6").Select
        ActiveCell.FormulaR1C1 = _
            "=SUMPRODUCT(('Data This Week'!$B$5:$B$992=B6)*('Data This Week'!$D$5:$D$992=D6)*('Data This Week'!$L$5:$L$992))-(SUMPRODUCT(('Data Last Week'!$B$5:$B$992=B6)*('Data Last Week'!$D$5:$D$992=D6)*('Data Last Week'!$O$5:$O$992)))"
    When I try to run the procedure, I get Run-time error 1004 "Application-defined or object-defined error". The line starting with "ActiveCell" gets highlighted by the debugger.

    The formula works fine when typed directly into the cell. So I have tried to use the macro recorder to record myself entering the formula, but then I get a message saying "Cannot be recorded."

    Why is this error occuring and what would I need to do to fix it?

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using VBA to enter a SumProduct formula into a cell

    You're using FormulaR1C1 but not entering in R1C1 notation.

    EDIT: PM a Mod to have thread moved to Excel Programming Forum

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1