+ Reply to Thread
Results 1 to 7 of 7

Macro To Import Selected Range From Closed Workbook Only When Needed

  1. #1
    Registered User
    Join Date
    12-31-2010
    Location
    Kathleen, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    27

    Macro To Import Selected Range From Closed Workbook Only When Needed

    Here's one I searched for a while and couldn't find what I was looking for. Hoping someone out there can help me and save me some time.

    I send out a Downtime Report every day which several different users log their data into JasonLog spreadsheet each shift on the DT Log worksheet. If 1 person has the spreadsheet open and another needs to enter their data, person creates a duplicate copy. Now I have to open up the Copy Of DT Log worksheet, copy their data then paste into the original, then send the report. Not hard but just time consuming. Is there a way to create a macro button that when pushed, will allow me to select the range of cells that need to be updated and then pull them in from the "Copy Of" spreadsheet. I am attaching a copy of the DT log that we enter. Both original file and "Copy Of" spreadsheet is always in the same place: S:\PROJECTS\Maintenance\Downtime

    I appreciated any and all feedback. Sorry if I did not explain this well enough.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    12-31-2010
    Location
    Kathleen, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Macro To Import Selected Range From Closed Workbook Only When Needed

    Let me try to clarify, I just read it and it may not make any sense.

    Is it possible to highlight/select a range of range of cells which will change, and have a macro button that will populate the range of cells I select with same range of cells from a copy of the original workbook?

    Is this possible???


  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro To Import Selected Range From Closed Workbook Only When Needed

    Just so i understand you want to be able to randomly highlight a selected range in workbook A, say B5:D24, run the macro, and have it copy the data from that same selected range in workbook B into workbook A?

    If this is the case it shouldn't be hard at all. Just want to make sure first.

  4. #4
    Registered User
    Join Date
    12-31-2010
    Location
    Kathleen, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Macro To Import Selected Range From Closed Workbook Only When Needed

    Yes, exactly..

    Want to highlight B5:D24 in worksheet "DT Log" of workbook "A", run the macro, and have it copy the same range from "DT Log" of workbook "B" (which is a closed copy of workbook A) and paste the highlighted section back into A.

    If you can help me with this, would be greatly appreciated...thanks!

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro To Import Selected Range From Closed Workbook Only When Needed

    Sorry it took me so long to get back to you. I actually had a hard time with this one, which is good I suppose because I was able to learn some new things. Here is the code:
    Please Login or Register  to view this content.
    Steps:
    1. Put the code in your master copy, JasonLog P2-2011.
    2. In the master workbook either select the range that you want to transpose or just select the upper left most cell, so if you were going to transpose Range A1:G10 you could just select cell A1.
    3. Run the macro "UpdateData"
    4. in the copy workbook either in the input box or with the mouse select the entire range on the copy sheet that you want to transpose over.
    5. Click ok

    Note: This will work if the workbook is open or closed. Just change the filepath. Make sure the extension is correct. Let me know.

  6. #6
    Registered User
    Join Date
    12-31-2010
    Location
    Kathleen, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Macro To Import Selected Range From Closed Workbook Only When Needed

    Well it didn't quite work but I'm much closer than before. Here's what happened when I ran the macro.

    In my open workbook, "JasonLogP2-2011", on worksheet "DT Log", I selected the range I needed to import from the closed workbook (Copy of JasonLogP2-2011).

    Hit my macro button. The "Copy Of JasonLogP2-2011 workbook opened, and it asked me to select the range.

    I selected and hit OK, and it pasted the data in some other range of "Copy of JasonLogP2-2011".

    Close...but how can I make it do this...
    1) Hit the macro button to select a range in JasonLogP2-2011
    2) Range is selected with the Application.Inputbox
    3) This same range is imported from "Copy of JasonLogP2-2011 and pasted into JasonLogP2-2011.

    Question...does the closed workbook have to opened in order to import data? I searched for hours and read several different opinions, some involving ADO which were completely over my head.

    Can't tell you how much I appreciate the help...I am learning with help from these applications I am asking help from...lots of fun...

    Here's the code I copied into the vba module.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro To Import Selected Range From Closed Workbook Only When Needed

    Let start with the first issue which is why it pasted it in the copy of the workbook. I bet that the extension on your main book is .xlsx while i set it to be a macro enabled book .xlsm. This snippet here:
    Please Login or Register  to view this content.
    Normally it would have thrown up an error saying that the workbook couldnt be found but since i put in the On Error Resume Next code it would probably bypass that and just paste on the active workbook, which is the range you selected from.

    Yes, you can run the macro with the copy workbook open.

    Either change the above code to match your file extension or resave your main workbook as a macro enabled workbook then try the steps again.

    Get back to me to let me know.

+ 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