+ Reply to Thread
Results 1 to 3 of 3

FormulaR1C1 to refer to workbook from text string

  1. #1
    Registered User
    Join Date
    02-08-2012
    Location
    Gloucester, MA
    MS-Off Ver
    Excel 2010
    Posts
    10

    FormulaR1C1 to refer to workbook from text string

    So i've got a little bit of a tricky problem here, i thought i had the right code but its coming out a little odd when i execute it, and i can't figure out why.

    I'm attempting to create a macro which will open a prompt to select a workbook using the GetOpenFilename command, so far, so good. I then want to use the FormulaR1C1 command to refer to a specific cell (C2) within the targeted workbook. This is the code i'm currently using:

    Please Login or Register  to view this content.
    The last line of code is where i am running into trouble.

    When i run the macro, the following string shows up in the next empty row.
    ='C:\Users\Alkuan\Documents\[Example.xlsmSummary]Example'!R2C3

    The correct reference should be :
    ='C:\Users\Alkuan\Documents\[Example.xlsm]Summary'!R2C3

    if i display the string 'targetfile' right before this step, it shows up as
    C:\Users\Alkuan\Documents\Example.xlsm

    Any guidance as to where i've gone wrong would be greatly appreciated!

    Thanks in advance.
    Last edited by Alkuan; 05-29-2012 at 05:12 PM.

  2. #2
    Registered User
    Join Date
    02-08-2012
    Location
    Gloucester, MA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: FormulaR1C1 to refer to workbook from text string

    If i attempted to change the last line of code to this:

    Please Login or Register  to view this content.
    then the link put into the cell shows up as
    ='[C:\Users\Alkuan\Documents\[Example.xlsm]Summary]Example.xlsm]Summ'!R2C3

    I'm really quite confused about how the syntax of this statement is effecting the outcome.

    Here is a different forum post i found that is somewhat related

  3. #3
    Registered User
    Join Date
    02-08-2012
    Location
    Gloucester, MA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: FormulaR1C1 to refer to workbook from text string

    I found a very clumsy workaround that does work, but there has to be a better way.

    Please Login or Register  to view this content.
    Where the cell A2 in calculation has the following formula in place.

    Please Login or Register  to view this content.
    This returns the part of the string after the last '\'. Which in this instance is the file name. By inputting this into the cell when the referenced workbook is open, it automatically is converted into the full reference when the workbook is closed at the end of the code.

    For example, if this string is input into A1. C:\Users\Alkuan\Documents\Example.xlsm
    A2 returns, Example.xlsm

    As i said, very clumsy and there must be a better way to achieve this.
    Last edited by Alkuan; 05-30-2012 at 10:11 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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