+ Reply to Thread
Results 1 to 5 of 5

Help to loop a task for copying and pasting data from multiple workbooks

  1. #1
    Registered User
    Join Date
    07-04-2018
    Location
    Stockholm
    MS-Off Ver
    Microsoft office 2013
    Posts
    2

    Help to loop a task for copying and pasting data from multiple workbooks

    Hi All,

    I have created the below macro using macro recorder, and need some help to loop the task until now more links in column C.

    Task:
    Open up a workbook via a hyperlink in column "C" on a master file, in the newly opened workbook copy a row of data in a hidden sheet and paste this data into the master file on the same row as the hyperlink, then close the file. and repeat this for the next hyperlink in the column until no more hyperlinks


    c d e f g
    4 hyperlink1.xlsm copied data from hyperlink1.xlsm copied data from hyperlink1.xlsm copied data from hyperlink1.xlsm copied data from hyperlink1.xlsm
    5 hyperlink2.xlsm copied data from hyperlink2.xlsm copied data from hyperlink2.xlsm copied data from hyperlink2.xlsm copied data from hyperlink2.xlsm
    6 hyperlink3.xlsm copied data from hyperlink3.xlsm copied data from hyperlink3.xlsm copied data from hyperlink3.xlsm copied data from hyperlink3.xlsm





    using macro recorder


    Sub Consolidation()


    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Windows("Masterfile.xlsm").Activate
    Range("C4").Hyperlinks(1).Follow


    Windows("hyperlink1.xlsm").Visible = True
    Sheets("hiddensheet").Visible = True
    Sheets("hiddensheet").Select
    Range("B4:E4").Select
    Selection.Copy
    Windows("Masterfile.xlsm").Activate
    Range("D4").Select
    ActiveSheet.Paste
    Windows("hyperlink1.xlsm").Activate
    Sheets("hiddensheet").Select
    ActiveWindow.SelectedSheets.Visible = False
    ActiveWindow.Close savechanges:=False

    Windows("Masterfile.xlsm").Activate


    Application.DisplayAlerts = False
    Application.ScreenUpdating = True

    End Sub

  2. #2
    Valued Forum Contributor PFDave's Avatar
    Join Date
    05-17-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2013
    Posts
    1,067

    Re: Help to loop a task for copying and pasting data from multiple workbooks

    Untested but this shouldn't be far off.

    Question really is where your data starts (I've assumed row 4) and if you data in hiddensheet is always the same range to be copied

    Please Login or Register  to view this content.
    Please do add reputation where you see fit, it's nice to be nice and we all enjoy a pat on the back

    Please also mark your thread as solved once it has been.

  3. #3
    Registered User
    Join Date
    07-04-2018
    Location
    Stockholm
    MS-Off Ver
    Microsoft office 2013
    Posts
    2

    Re: Help to loop a task for copying and pasting data from multiple workbooks

    works great thankyou.

    I still have one complication.
    The "DisplayAlerts = false" does not prevent the microsoft prompt "some files can contain viruses.................. Would you like to open this file?"

    I have tired adding the site to trusted locations, searching to change the trust settings some are restricted to me on this computer. and i can't bypass it, meaning instead of letting the macro run, i would have to click during each loop when the prompt comes up. Is there another way to bypass this, or a code that would select ok when the prompt appears?

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,288

    Re: Help to loop a task for copying and pasting data from multiple workbooks

    Hi snowcrash79

    Welcome to the Forum.
    In future please view the forum rules before posting. Your post does not comply with rule #3.
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing.
    So, do the following:
    Edit your post, highlight your code and click the [#] button at the top of the post window.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Valued Forum Contributor PFDave's Avatar
    Join Date
    05-17-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2013
    Posts
    1,067

    Re: Help to loop a task for copying and pasting data from multiple workbooks

    Quote Originally Posted by snowcrash79 View Post
    works great thankyou.

    I still have one complication.
    The "DisplayAlerts = false" does not prevent the microsoft prompt "some files can contain viruses.................. Would you like to open this file?"

    I have tired adding the site to trusted locations, searching to change the trust settings some are restricted to me on this computer. and i can't bypass it, meaning instead of letting the macro run, i would have to click during each loop when the prompt comes up. Is there another way to bypass this, or a code that would select ok when the prompt appears?
    https://support.microsoft.com/en-gb/...007-office-pro

+ 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. Replies: 2
    Last Post: 09-06-2015, 02:57 AM
  2. [SOLVED] Copying data from other workbooks and pasting into master workbook
    By jcook1100 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-15-2013, 08:03 AM
  3. Conditioned copying/pasting of specific cells from multiple workbooks to master workbook
    By Ziad Homaidan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-06-2013, 11:39 AM
  4. Replies: 1
    Last Post: 11-21-2012, 11:23 AM
  5. Replies: 1
    Last Post: 07-20-2012, 06:20 PM
  6. Conditional copying and pasting data between two workbooks
    By svt06 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-02-2012, 11:25 AM
  7. [SOLVED] Loop for copying data, then pasting in a continuous row
    By Bhupinder Rayat in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-07-2006, 11: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