+ Reply to Thread
Results 1 to 6 of 6

Reference a WB with filename based on cell value in current WB(subscript out of range)

  1. #1
    Registered User
    Join Date
    10-28-2015
    Location
    Krakow
    MS-Off Ver
    2003/2013
    Posts
    37

    Reference a WB with filename based on cell value in current WB(subscript out of range)

    Hi,

    I've been trying to get this to work for ages now and I can't get my head arount it but I feel like it should be doable.

    I want to open another workbook from which I get data, paste it into the current workbook, then modify and paste into yet another one.

    However these other workbooks have filenames that may change and I want to input the filename that interests me e.g. in cell C4.

    I would love to cut down on the code and not have to use Workbooks.Activate each time...


    Current code excerpt:
    Please Login or Register  to view this content.

    The code that fails:

    Please Login or Register  to view this content.
    It gives the "subscript out of range" error each time on the "Set wb" row.


    I wonder if this is possible and if so, what am I doing wrong...

    Cheers and all the most Excel-lent in 2016
    Cloudberr

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

    Re: Reference a WB with filename based on cell value in current WB(subscript out of range)

    Hi there,

    If the workbook is already open try:

    Please Login or Register  to view this content.
    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,565

    Re: Reference a WB with filename based on cell value in current WB(subscript out of range)

    If the intention is to open a workbook, then you need to use Workbooks.Open

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    10-28-2015
    Location
    Krakow
    MS-Off Ver
    2003/2013
    Posts
    37

    Re: Reference a WB with filename based on cell value in current WB(subscript out of range)

    Hiya,

    Both of these work!

    It's funny but I'm certain I've tried something with Workbooks.Open and especially something like in Greg's version, but still couldn't get there.

    I've tested these with three workbooks open to see if copy-pasting works correctly between them and it does as it's supposed to. I'm super happy now.

    I'll probably be using the TMS's code since it's a bit more concise - it makes sense to open it and reference it in one go I think.

    Big thanks guys :-)

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,565

    Re: Reference a WB with filename based on cell value in current WB(subscript out of range)

    You're welcome. Thanks for the rep.

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

    Re: Reference a WB with filename based on cell value in current WB(subscript out of range)

    Hi again,

    Many thanks for the Reputation increase - much appreciated

    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. [SOLVED] Lock a range of cells base on current date relative to cell reference
    By egchristensen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-13-2015, 05:11 PM
  2. [SOLVED] Reference cell on another worksheet based on value on current sheet
    By clocke in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-19-2014, 12:24 PM
  3. [SOLVED] save as with current filename plus cell reference text
    By AWITCHER in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-14-2014, 10:00 AM
  4. Edit filename in Formula with reference to a cell in current file
    By yatin1964 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-29-2013, 09:35 AM
  5. Help with formula of filename and saving filename as current time
    By hqradio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2012, 06:10 AM
  6. Reference filename based on cell contents
    By Scrap74 in forum Excel General
    Replies: 3
    Last Post: 01-06-2010, 08:36 PM
  7. [SOLVED] I want a cell to show the current filename automatically.
    By Troy in forum Excel General
    Replies: 4
    Last Post: 01-31-2006, 10:35 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