+ Reply to Thread
Results 1 to 2 of 2

Copying data from one excel file and pasting into multiple excel files

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Lafayette, LA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Copying data from one excel file and pasting into multiple excel files

    I a trying to get this macro to work for my problem. I need to copy cells from one workbook and paste them into multiple workbooks. The macro I am trying to use is below. The code fails when I try to activate the sheet to paste the copied cells to (see Workbooks.Activate (FolderName & Fname) below).

    Sub LoopThroughFiles()

    FolderName = "S:\CRT-General Equipment Forecast Lists\2015 Forecast Information\2015 Country Templates\11-26-14 backup"
    If Right(FolderName, 1) <> Application.PathSeparator Then FolderName = FolderName & Application.PathSeparator
    Fname = Dir(FolderName & "*.xls")

    'loop through the files
    Do While Len(Fname)
    With Workbooks.Open(FolderName & Fname)
    ' here comes the code for the operations on every file the code finds
    'HERE if you want to execute the second macro for every file in the loop
    Copy_discounted_costs_to_country_forecasts
    End With
    ' go to the next file in the folder
    Fname = Dir
    Loop

    End Sub
    Sub Copy_discounted_costs_to_country_forecasts()
    '
    ' Copy_discounted_costs_to_country_forecasts Macro
    '
    '
    Windows("2015 Shortage Reconcile w Revised Discounted Costs.xlsm").Activate
    Range("L1").Select
    ActiveWindow.ScrollRow = 326
    ActiveWindow.ScrollRow = 321
    ActiveWindow.ScrollRow = 302
    ActiveWindow.ScrollRow = 186
    ActiveWindow.ScrollRow = 3
    Range("L5:L1669").Select
    Selection.Copy
    Workbooks.Activate (FolderName & Fname)
    Range("E8").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    End Sub

    Thanks in advance for any help with this...I am new to VBA.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copying data from one excel file and pasting into multiple excel files

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    MAybe:

    Please Login or Register  to view this content.
    Last edited by xladept; 11-26-2014 at 06:42 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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. Opening 4 excel files, copying set table data and pasting into "master file".
    By Belloni in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-29-2012, 09:50 AM
  2. [SOLVED] I need a macro for copying the data of all excel files into one sheet of a excel file.
    By pavan_yuvaraj in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-18-2012, 09:23 AM
  3. Macro for copying specific data from excel files in a folder to a newly created excel file
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2012, 02:24 PM
  4. [SOLVED] copying data from several files to one excel file
    By sharman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2006, 09:40 AM
  5. [SOLVED] Macro copying info/data in multiple excel files into one summary file.
    By Jskasango in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-06-2006, 03:30 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