+ Reply to Thread
Results 1 to 9 of 9

Copy a cell value from multiple closed workbooks into a new workbook

  1. #1
    Registered User
    Join Date
    01-30-2017
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    5

    Copy a cell value from multiple closed workbooks into a new workbook

    Hi everyone,

    I am a complete novice in VBA, but I am very interested in learning as much as possible. Basically what I have is a bunch of excel files, each of them containing a value in cell J48. What I need is, to copy these values from cell J48 from the closed workbooks and put it into a new workbook. The number of closed workbooks is huge, here I just entered 3, do you guys have any suggestions?

    Sub consolidateData()
    Range("A1").Select
    ActiveCell.Value = "Unsold Position"
    Range("A2").Select
    ActiveCell.Value = "Tangible Net Worth"

    Range("A2").Select
    Workbooks.Open Filename:="P:\1 Financial Accounting\Clotures 2016\Weekly Position Report 2016\Intermediary Valuation of unsold Position WK 2 2016.xlsx"
    Workbooks.Open Filename:="P:\1 Financial Accounting\Clotures 2016\Weekly Position Report 2016\Intermediary Valuation of unsold Position WK 3 2016.xlsx"
    Workbooks.Open Filename:="P:\1 Financial Accounting\Clotures 2016\Weekly Position Report 2016\Intermediary Valuation of unsold Position WK 4 2016.xlsx"

    Windows("consolidate").Activate
    Range("A1:A55").Select
    ActiveCell.Value

    Selection.Consolidate Sources:=Array( _
    "'P:\Weekly Position Report 2016\[Intermediary Valuation of unsold Position WK 2 2016.xlsx]Sheet1'!J48", _
    "'P:\Weekly Position Report 2016\[Intermediary Valuation of unsold Position WK 3 2016.xlsx]Sheet1'!J48", _
    "'P:\Weekly Position Report 2016\[Intermediary Valuation of unsold Position WK 4 2016.xlsx]Sheet1'!J48")
    Windows("Intermediary Valuation of unsold Position WK 2 2016.xlsx").Activate
    ActiveWorkbook.Close

    Windows("Intermediary Valuation of unsold Position WK 3 2016.xlsx").Activate
    ActiveWorkbook.Close

    Windows("Intermediary Valuation of unsold Position WK 4 2016.xlsx").Activate
    ActiveWorkbook.Close

    End Sub

  2. #2
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Copy a cell value from multiple closed workbooks into a new workbook

    Is it only the week number that is different in each of these workbooks? The rest of the file path is the same? If so, you can do it with a loop.

  3. #3
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Copy a cell value from multiple closed workbooks into a new workbook

    Welcome. We like novices who want to learn.

    Firstly, when posting segments of code put them inside [ code ] [ /code ] tags (without the spaces)

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Copy a cell value from multiple closed workbooks into a new workbook

    Please Login or Register  to view this content.
    No need to select and then write to, you can do this with

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Copy a cell value from multiple closed workbooks into a new workbook

    For looping through the source workbooks try:


    Please Login or Register  to view this content.
    You also might want to think about copying from one source workbook at a time or you could find Excel creaking with 100s of open workbooks. If your filenames aren't just increasing week numbers then you'll have to come up with some fancy maths which basically say if counter > 52 then year = year + 1, counter = 1.
    Last edited by BellyGas; 01-30-2017 at 10:37 AM.

  6. #6
    Registered User
    Join Date
    01-30-2017
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy a cell value from multiple closed workbooks into a new workbook

    This is exactly what I was looking for! thank you so much!

  7. #7
    Registered User
    Join Date
    01-30-2017
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy a cell value from multiple closed workbooks into a new workbook

    Thank you very much, just one more question. How can I copy the J48 values from all workbooks next to "Unsold Position" in my open workbook?

  8. #8
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Copy a cell value from multiple closed workbooks into a new workbook

    Depends how 'unsold position' is configured.

    If it's a column and each value is to be copied into the next row then you can choose the next row with no data in it with:

    Please Login or Register  to view this content.
    Where A1048000 is the bottom of the column in question. So you could just do something like

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-30-2017
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy a cell value from multiple closed workbooks into a new workbook

    [file number ffkdjsflksdj][/CODE]

+ 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. Macro to get values from multiple closed workbooks into single open workbook
    By aman2059 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-10-2015, 08:36 AM
  2. Copying rows from multiple closed workbooks to active workbook
    By onbeillp111 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2013, 11:19 AM
  3. [SOLVED] Copying cells from multiple closed workbooks to active workbook
    By Anonym216 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2013, 07:53 AM
  4. Extract data from closed workbooks and copy into new workbook
    By philaugust2004 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-15-2013, 07:45 AM
  5. Copy Sheet from one Workbook to Multiple Closed Workbooks
    By sflexi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2013, 10:01 AM
  6. copy a range from 2 closed workbooks to opened workbook
    By ahsanzafar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2012, 08:40 PM
  7. Copy Data to One Workbook From Multiple Closed Workbooks
    By Ben4481 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-04-2010, 08:02 AM

Tags for this Thread

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