Results 1 to 4 of 4

Using variables in VBA formula functions

Threaded View

  1. #1
    Registered User
    Join Date
    10-05-2013
    Location
    indonesia
    MS-Off Ver
    Excel 2013
    Posts
    6

    Using variables in VBA formula functions

    Dear all,

    As a beginner in VBA, I'm pleased to write my first post.
    Here is my problem:
    I want to use excell functions in VBA to retrieve data from a closed workbook.
    My formula uses SumProduct function (because I understood that SumIf works only with an open workbook) and I want to create a loop to fulfill directly all the cells (from 0 to 16 of the column A) with the result of this same formula.
    But when I use the variable "i" (indicating the row) into the SumProduct function using the quote (A"&i&"), I have a compile error "Syntax error".
    Sorry it's probably basic, but as a beginner, I already spent hours on it without finding any solution...

    This formula works without any problem when used in a cell of Excell, so I used perhaps the formula in the wrong way.

    Please find my code below:
    Dim Result As Range
             Dim i As Integer
             i = 0
             While i <= 16
                 Set Result = Sheets("Report per cost center").Range("E" & i)
                 With Result
                    .Formula = "=SUMPRODUCT(--('D:\Personal Costs\2013\2. Database\[Personal Costs - 2013-V10.xlsx]Actual 2013'!$A$5:$A$52=A"&i&"),'D:\Personal Costs\2013\2. Database\[Personal Costs - 2013-V10.xlsx]Actual 2013'!$L$5:$L$52)"
                    .Value = .Value
                 End With
                 i = i + 1
             Wend
    I hope I am clear enough for your understanding.

    Thanks a lot in advance for your support.

    Regards,

    Eric
    Last edited by alansidman; 10-05-2013 at 07:30 AM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] variables for ranges and their use in functions.
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-12-2013, 04:02 PM
  2. Using variables within functions in a macro.
    By Talofa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2012, 10:33 AM
  3. Using Variables in Functions
    By bucket7200 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2011, 07:46 PM
  4. Count functions with variables
    By JohnathanC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2010, 12:11 PM
  5. [SOLVED] LOGICAL FUNCTIONS WITH MULTIPLE VARIABLES
    By luiss in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-18-2005, 12:08 PM

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