+ Reply to Thread
Results 1 to 5 of 5

Variable in formula

  1. #1
    Registered User
    Join Date
    06-28-2018
    Location
    France
    MS-Off Ver
    2016
    Posts
    2

    Variable in formula

    Hi there!

    Firstly thank you all for your help, I've found all the solutions to my problems so for on this forum!

    Unfortunately I am unable to find a solution to this particular problem, maybe you could help:

    I have a workbook with multiple worksheets, on which are a lot of raw data by year (one year per sheet), and a sheet where I extract selected data for analysis.

    I am writing a VBA code to automatically go look for this selected data using index/match. My code so far works correctly and inserts the formula in the cells:

    Please Login or Register  to view this content.
    This goes looking for the data that I want on the 2016 sheet.

    Now I would like to use a variable to automatically change all the "2016" in the formula to a variable, so that the people I work with only have to press a button to add a new year to the anlysis sheet.

    I've set the variable as:
    Please Login or Register  to view this content.
    How can I integrate the variable "YEAR" in my formula ?

    Sorry, this is quite a basic question but I cannot find on Google an explaination as to how this works and I'm learning as I go.

    Thanks very much!

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Variable in formula

    1. I wouldnt use a word like YEAR as a variable, it may be reserved. Perhaps WYear ?

    2. Am no VBA expert but expert, but try

    Please Login or Register  to view this content.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Variable in formula

    Hi there,

    Does the following code get you moving in the right direction?

    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  4. #4
    Registered User
    Join Date
    06-28-2018
    Location
    France
    MS-Off Ver
    2016
    Posts
    2

    Re: Variable in formula

    Thank you very much Special-K and Greg!

    It works wonderfully! I actually had an issue with the variable type, which I noticed when you suggested using an Integer.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Variable in formula

    Hi again,

    Many thanks for your prompt feedback and also for the Reputation increase - much appreciated

    You're very welcome - glad I was able to help.

    Best regards,

    Greg M

+ 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. Variable in .Formula
    By radddogg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2017, 12:58 PM
  2. [SOLVED] How to put variable into formula?
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2015, 03:17 AM
  3. Changing column variable on a copied formula instead of row variable
    By dsw283 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-06-2014, 04:13 PM
  4. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  5. Using a variable in a formula
    By tsutter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2008, 06:56 PM
  6. Replies: 1
    Last Post: 10-31-2006, 08:34 AM
  7. variable in a formula
    By jobra in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2005, 04:05 AM

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