+ Reply to Thread
Results 1 to 3 of 3

Referring to workbooks with variables

  1. #1
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Referring to workbooks with variables

    Hello.

    I have two workbooks called RTB and NSG. I want to create a macro that transfers data from RTB (sheet 34 specifically) to NSG (sheet 4), but sometimes the person who manages RTB adds a column. If I set up a macro to transfer the data from column F, for example, if the admin adds a column before, then that column will be column G and my macro will transfer the wrong data.

    I want to add a validation process at the beginning of the Macro to verify the columns and names have not changed. I am trying to refer to the workbooks as variables, however, I am having a problem with referring to separate workbooks. for example, the following code is giving me a Runtime error 9 'subscript out of range' on the last line.

    Please Login or Register  to view this content.
    Any idea what is causing this? thank you in advanced.

    PS: the macro is being stored in the NSG workbook. Thanks

  2. #2
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Re: Referring to workbooks with variables

    so I guess it is a syntax error. the line works if I change
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    but I remember using the other syntax. Am I getting it confused with another programming language?

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Referring to workbooks with variables

    Please Login or Register  to view this content.
    This is valid syntax. Double check the sheet name is exact. Is there a space in between ("sheet 34") or trailing ("sheet34 ") ?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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. Referring to UserForm and Control via Variables
    By BanginMyHeadOnMyDesk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2016, 11:31 AM
  2. Referring to Open Workbooks
    By mpa15 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2011, 05:17 AM
  3. Referring to other workbooks via VBA code
    By alexthecheese in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-06-2009, 01:59 PM
  4. referring to open workbooks
    By toddgak in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-27-2009, 07:36 PM
  5. Referring (quickly) to nearly 200 workbooks
    By Brigitte_P in forum Excel General
    Replies: 2
    Last Post: 04-18-2008, 01:22 PM
  6. referring to objects using string variables?
    By Baapi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2007, 02:34 PM
  7. [SOLVED] Referring to other workbooks
    By jkitzy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2005, 11:06 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