+ Reply to Thread
Results 1 to 4 of 4

Using variables in VBA formula functions

  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:
    Please Login or Register  to view this content.
    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

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using variables in VBA formula functions

    a very little mistake, missing spaces
    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Using variables in VBA formula functions

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (I have added them today. Please adhere to our rules in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

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

    Re: Using variables in VBA formula functions

    Thank you very much Patel45 for your great reactivity, it works perfectly!

    @alansidman : Understood, I will next time.

+ Reply to Thread

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