+ Reply to Thread
Results 1 to 6 of 6

Get a value from another workbook

  1. #1
    Registered User
    Join Date
    05-10-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Question Get a value from another workbook

    How do you copy a value from another workbook using VBA code? For example copy range("D4") of workbook2, and pasting the value on Range("J18") of the active workbook.
    Also, is it possible to have workbook2 be closed, or not show it?

    Thanks in advance!

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Get a value from another workbook

    For the first part of your question perhaps a macro like this?

    Please Login or Register  to view this content.
    Yes it's also possible to read data from a closed workook. Depending of how much data you may whis to read it can sometimes be faster to open the workbook, read data and close the workbook.

    See link for reading data from closed workbook.
    http://spreadsheetpage.com/index.php..._a_closed_file

    Alf

  3. #3
    Registered User
    Join Date
    05-10-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Get a value from another workbook

    Thank you! How could you write an if function saying If cell E4 of workbook2 has a value, then cell D5 will be copied and pasted on cell J18 of the active workbook?
    The macro will only copy cell D5 of workbook2 If cell E4 has a certain value.

    Thanks again!

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Get a value from another workbook

    Like this probably:

    Please Login or Register  to view this content.
    Alf

  5. #5
    Registered User
    Join Date
    05-10-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Question Re: Get a value from another workbook

    Thank you again alf!
    Is there anyway that workbook2 be closed while the macro is running? (I'm running this macro from the currently active workbook).

    Many Thanks!

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Get a value from another workbook

    Is there anyway that workbook2 be closed while the macro is running?
    Yes there is. Check the link I added in post #2 where this technique is described.

    Alf

+ 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