+ Reply to Thread
Results 1 to 7 of 7

referencing variable help

  1. #1
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    referencing variable help

    Hi Guys,

    So i have a bunch of formulas which calculate a linked workbook and im wanting to have a cell in the current workbook which you can enter the filename so that it is easily updated without going into the VBA.

    =COUNTIF('C:\Users\webbth\Desktop\[South Pac Load Tracker - MAR14.xlsx]SPECIALS TEAM NZ'!$C$8:$C$1000,A4)

    This is the formula for example in the cell, and i want to change [South Pac Load Tracker - MAR14.xlsx] to a cell in the workbook instead.

  2. #2
    Registered User
    Join Date
    05-29-2013
    Location
    IL, USA
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: referencing variable help

    if the cell that contains the file name is static, then try
    =COUNTIF("'C:\Users\webbth\Desktop\"&B4&"SPECIALS TEAM NZ'!$C$8:$C$1000",A4)
    where B4 contains [South Pac Load Tracker - MAR14.xlsx]

    Good luck,
    Josh

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,922

    Re: referencing variable help

    Use the Indirect function to reference the contents of a cell

    http://www.techonthenet.com/excel/formulas/indirect.php
    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
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: referencing variable help

    You may use INDIRECT:

    =COUNTIF(INDIRECT("'C:\Users\webbth\Desktop\["&A1&"]SPECIALS TEAM NZ'!$C$8:$C$1000"),A4)

    or if you wish in code:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  5. #5
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    Re: referencing variable help

    Why is it when update my links they come up with #VALUE yet the filepath and formulas are correct .... and if i manually re-enter it with the workbook open they will stay its not until i try and update with the workbook closed that they do not calculate


    Thanks izandol, stupid me used ' instead of " and used like this

    dim filename as string

    filename = sheets(sheet1).Range("a1").value

    Activecell.Formula = "=COUNTIF('C:\Users\webbth\Desktop\[' & filename & ']SPECIALS TEAM NZ'!$C$8:$C$1000,A4)"

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: referencing variable help

    INDIRECT and COUNTIF functions do not work with closed source workbook.

  7. #7
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    Re: referencing variable help

    i see.... i guess that means ill have to write a vba script to update values which will simply check if workbook is open if not then open workbook then (the countif functions should then auto update as the source is open) then simply close the workbook straight away.

    did ^ and it works. thanks guys
    Last edited by 13lack13lade; 03-11-2014 at 12:07 AM.

+ 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. referencing range w/ variable
    By dej222 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2009, 08:18 PM
  2. Variable referencing?
    By nasbcn in forum Excel General
    Replies: 2
    Last Post: 01-25-2008, 11:33 AM
  3. Variable Cell Referencing
    By 0-0 Wai Wai ^-^ in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-16-2006, 04:40 AM
  4. Referencing variable in a loop
    By JeffMelton in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2006, 11:25 PM
  5. Help with referencing variable range
    By Cutter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2005, 05:20 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