Macro To Copy Data From Two Workbook To Another Where All Workbooks Are Open

Jun 7, 2014

I have 3 workbooks open. 1 is my working file and I name it as "Final[date].xlsm". The other 2 files are my source files which are also open are named as source1.xlsx and source2.xlsx. Both the source files has only one tab/sheet as "Sheet1". My objective is to bring the contents of the source file to my working file in 2 different sheets. all the contents in Sheet1 of "Source1.xlsx" should be paste.values only to the "Final[date].xlsm" with a sheet name "BankDetails". This will enable the user also to replace the old data in "BankDetails" tab. The "source2.xlsx" sheet1 has a different situation. I need to copy only the cells with values, not the entire cells, because it has to be pasted (values only) to range C2:L. I have formulas in the other columns before C and after L.

Take note that my working file name is changing every based on the date while my source file has always same file name.

View 12 Replies


Macro To Copy Data From Open Workbooks

Feb 12, 2009

I'm just starting out on my journey into VBA and this forum has been a valuable resource for picking up hints and tricks

I've decided to cut some corners and ask for help for the final piece of my current jigsaw - effectively this comes in two bits.

Part one:

I want to copy a sheet from two open workbooks and paste them into my active wookbook. Both source workbooks only have one sheet. I want a dialogue box to select the desired workbook, select and copy all data and then paste to a specified sheet (replacing the current data) in the destination workbook. I then want to select the other source workbook from the dialogue box and copy all data to a separate sheet in the destination workbook. I would like the dialogue box to have two options - Ok to select, copy and paste data, Cancel to end the macro.

Part two:

I want to copy a sheet from my source workbook and paste it as a separate sheet in a new workbook (a one page workbook would be ideal). I then want to save the new workbook in a specified location as "Data - Date" in the format 2009 02 12.

View 9 Replies View Related

Macro Copy Data From Multiple Workbooks Into Master Workbook

Aug 4, 2012

I have 17 workbooks which contain similar data and formatting. The only variance is the number of rows of data in each. I want to write a macro in the Master worksheet that will accomplish the following

1. Create a worksheet name in the master workbook with the same name as the workbook that it's pulling data from.
2. Copy over the column headings from columns A:P to the newly created worksheet on the master workbook
3. Copy over all rows that contain the word "down" under column D titled Operational status

The naming convention for the master workbook will be titled "All Switches". The naming convention for the worksheets containing the data are titled Port_Map_on_tiegcsw01, Port_Map_on_tiegcsw02, Port_Map_on_nypgcsw01. There are other names , but I can reference the code an update accordingly.

I found some searches on the forum for creating a macro to copy data between workbooks, but not quite sure how to write the macro for the three functions.

View 2 Replies View Related

Open 2 Workbooks Then Copy A Sheet From 1 Workbook To Another?

May 11, 2012

I'm trying to do something which I believe is simple but my lack of VBA knowledge is getting in the way. How do I open 2 workbooks then copy a sheet from 1 workbook to another?

I can get the workbooks open just can't copy the sheet across? I get a run time error 9, subscript out of range message on copy sheets code


Private Sub CommandButton1_Click()
'locate file via range and open the document'


View 2 Replies View Related

Excel 2007 :: VBA To Save And Close All Open Workbooks Except Macro Workbook?

Mar 8, 2013

I have a macro that opens all workbooks from one directory and runs a macro for each workbook to clean up the data. I cannot figure out how to take all those open workbooks and save them to another directory and close the workbook. Also, I do not want the macro workbook (xlsm) to save. I only want it to close. I am working in 2007 Excel.

View 8 Replies View Related

Open Files & Copy Data Between Workbooks

Sep 15, 2007

Simply trying to copy data from one worksheet to another. The source sheet is an excel file exported from an Access table. I recorded the macro using the recorder in Excel because I am no programmer, but when I try to run the code, I get this error:

"Code execution has been interrupted" ...and the Range I tried to select in the source file is highlighted by the Editor.

Is the source file protected somehow?

My ______________________________________________________________________________

Private Sub Workbook_Open()

ChDir "P:Databasesdownloads"
Workbooks.Open Filename:="P:Databasesdownloadsheadersflat.xls", Origin:= _
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select

View 9 Replies View Related

Import Data From Several Closed Workbooks To A Single Sheet In An Open Workbook

Aug 3, 2009

I need to import the data from a specific sheet (same named sheet on all closed workbooks) to a sheet in an open workbook. All the columns are identical in every workbook but the number of rows is variable, so the data from each subsequent workbook must be appended to the end of the current data.

Whenever a button is pressed, this macro will clear the sheet, then import the data starting in A3. The workbooks are in different folders but they all have the same name, so some sort of explorer window will probably be needed to actually select each file.

View 3 Replies View Related

Modify Existing Macro To Copy To Different Workbook Instead Of Open Workbook?

Dec 7, 2012

Here's my macro:

Sub CopyRow()'
'Copies row to new sheet, highlights it, marks column 'A' as copied.
Dim cCell As Range
Set cCell = Selection.Cells(1, 1)

[Code] .....

Is it possible to modify it to paste into a different workbook called c:filesDestination.xlsm, instead of the existing workbook (Source.xlsm)? The destination sheet name is the same (Sheet2). It's OK if both workbooks are open at the same time.

View 2 Replies View Related

Copy Data From Workbook / Open Existing Workbook - Select Range And Paste

Mar 26, 2012

Copy data from workbook, open existing workbook, select range and paste. But my copied data is lost.

Sub Select_Copy_Paste()

[Code] .........

' Here i need to do something to paste data into r.address?

View 4 Replies View Related

More Than One Reference Workbooks To Copy Cells To One Workbook / Macro

Nov 6, 2012

I have Book1 (reference workbook) and Book2 (where i copy values from Book1)

Now I have macro to fetch the datas and paste the values in the format below.

But I can only doing this for one reference workbooks. But i need to add more reference workbooks in a file and paste to Book2. (etc: Book1, Book3, Book4, ....... to Book2)

Book2 looks like:

A1 B1 C1 D1
Name Adress Age Sex
Ozan xxxxxx 27 M

Here' s the Code.

Option Explicit
Sub TransferData()
Dim wkb As Workbook, wks As Worksheet, LastRow As Long
Dim FilePath As String, FileName As String
Dim ws As Worksheet, blnOpened As Boolean
'Change these variables as desired...

[Code] ........

View 3 Replies View Related

Copy Data From Multiple Workbooks Into One Workbook?

Aug 13, 2014

I'm trying to set up an excel that will allow me to gather data from multiple workbooks and get it into one master worksheet. All of the worksheets are formatted the same way (See below)

Employee Last Name
Employee First Name
Employee Position
Employee Series Number
Departing City
Departing State
Attended Pilot Training?

We don't have the data yet so the idea is to paste this information into their perspective worksheets and then have them automatically populate into the master tab.

View 1 Replies View Related

Copy Data From Different Workbooks In One Master Workbook?

Dec 14, 2011

I have got a file with a lot of different workbooks

What i want to do, is open each one of them, copy a range of cells, for example E4:E15, then open the "master" workbook, look in row 4 which cell is empty and then paste the data there

i know how to copy-paste from one workbook to another, i am just not sure how to do it for more than one workbook.

View 2 Replies View Related

Prompt Open Closed Workbook Then Copy Range And Paste Special Into Open Workbook

Apr 6, 2013

I have created a spreadsheet some time ago and have been asked to improve on it but I'm rusty with VBA.

I have an automated ordering system that saves each sent order as the date e.g "05-04-2013.xls" but the management team want a graph with the data for the last 4 weeks compared. I have created a seperate workbook called "consumables report.xls" which has a column with the products listed followed by columns "Quantity" and "cost" which is repeated for the 4 weeks of the month.

I want to add a button to prompt the user to choose the saved order e.g "05-04-2013.xls" (all orders saved in same directory) to copy and paste the quantity and cost columns (c8,D69) into "consumables report.xls". I got this to work earlier but it would only paste the formulas and not the values. So I need

A prompt to open workbook
Copy range (c8,d69)
Close work sheet
Paste special .value (c8,D69)

I dont care if it has to open the workbook to copy the data as this will only be used once a month so it dosnt matter how slow the code is.

week 1 week 2 week 3 week 4


View 7 Replies View Related

Compare Two Ranges In Different Workbooks And Copy Data To A 3rd Workbook

Jul 30, 2004

I have two spreadsheets in different workbooks ( workbook 1: sheet 1 and workbook2: sheet1), here i need to compare column 5 in Book1 and Column 5 for all cells, say X is the value we are looking for..

X occurs once in book1 and might occur more than once in if a match occurs ( that is once the code checks that there is X occuring in both books in columns 5) it should copy all rows in book 2 where X occurs to a new workbook 3 in sheet 1 and also it shoud copy entire row data where X occurs in book 1 sheet 1 . But this data from book 1 has to be copied at the end of row after the data from book 2 has been copied.

if X occurs 4 times in book 2 , then 4 rows have to be copied in book 3 and then data from Book 1 where X occurs only once is copied 4 times at the end of the data from book 2.

this process has to repeated for all cells in columns 5 in book1 and column 5 in book2 .

Sub Find_Matches()

Dim M, N As Range, x As Variant, y As Variant
Dim NewRange As Range

To get the book1 location

MsgBox " Selec the Location of N File"

Application.Dialogs(xlDialogOpen).Show arg1:=""


Sheets("sheetA").Select .......................

View 9 Replies View Related

Excel 2003 :: Macro To Copy And Paste Special Values From Different Workbooks Into One Workbook

Nov 24, 2012

Copy over data from different workbooks and using paste special values to paste it into a new workbook using a macro. Here is what I have and what I am looking for:

My file path is

C:Documents and SettingsMy DocumentsProjectCostsDecember12

In this folder I have workbooks called:


In each workbook I have 4 worksheets


I also have a workbook called DecMonthlyTotal in the same folder with the same named worksheets.

I am looking for a macro to be placed in the DecMonthlyTotal that will pull the data from the Cashable12-13 worksheets from Function1, Function2 and Function3 and paste special the values into workbook DecMonthlyTotal, worksheet name Cashable12-13, it will also pull the data from the NonCashable12-13 worksheets from Function1, Function2 and Function3 and paste special the values into workbook DecMonthlyTotal, worksheet name NonCashable12-13

Both the Cashable12-13 and the NonCashable12-13 have Columns A - G The row that the macro should start the copying from is Row 3 for each of the workbooks; however I don't have an end row for the workbooks as this will vary.

I am using Excel version 2003.

View 1 Replies View Related

Copy Data From Multiple Workbooks To Single Workbook In Another Location Using VBA

Jun 10, 2014

I have a folder which contains multiple 'Customer' workbooks (example attachment 'Customer_001'). Each workbook has a filename unique to the customer (Customer_001, Customer_002, Customer_117 etc). The workbooks contain a single sheet with customer information and answers to questions. These 'Customer' workbooks are automatically saved into a folder once the customer completes a Userform and clicks 'save'. Potentially, there could be 100's of customers' workbooks saved in the folder, each with their own unique filename.

I also have a 'Master' sheet saved in a different folder (example attachment 'Master'). The 'Master' workbook has multiple sheets named 'Department 1' and 'Department 2'. The purpose of the master sheet is to consolidate all information from the individual customers' workbooks.

Specifically, I would like a command button on the 'Master' workbook to execute the following tasks...

1. Copy the data from range A3:F3 from each of the 'Customer' workbooks held in the folder.
2. Paste the data into the next blank row on the 'Department 1' sheet in the 'Master' workbook.

3. Copy the data from range A7:F7 from each of the 'Customer' workbooks held in the folder.
4. Paste the data into the next blank row on the 'Department 2' sheet in the 'Master' workbook.

5. Save the 'Master' workbook.
6. Delete all 'Customer' workbooks in the folder.

View 3 Replies View Related

Copy Data From Child Workbooks And Paste In Master Workbook

May 25, 2009

I had to copy data from child woekbooks (*.xls) and paste it to the master workbook with same page to page every time when a macro is executed i had done the copy and paste part

But I'm Facing the problem in which i had to deal with

Validations as on both master and child sheet validation (column based combo box is activated )
one is worktype
2ns is time type

i jst had to copy data to the master macro works perfectly fine but the problem is that a msg box appears which signifies that i had to change the name (version ) for both types when i click yes 2 times it pastes the data

I'm attaching my macro as well as pic of that msg box with this attachment

View 6 Replies View Related

Copy Data From Different Workbooks / Worksheets And Paste In Master Workbook?

Apr 29, 2014

I get 'x' number of workbooks(with one sheet only) everyweek from which I need to copy data and paste to a master worksheet. (SCREEN CAPTURE BELOW)

I am unable to write the code myself as I have never worked on VBA and am only a beginner.

Part I:

The data I need to copy starts from the 19th row (A19:H19). The end point is determined by the row just before the row that has the words "Calibration Request" in it.

Part II:
Just below the data that was pasted from Part I, the data from 2 rows below the words "Calibration Request" needs to be pasted. The end point for this would be a blank row encounter.

Also some of the rows and columns are merged.

View 9 Replies View Related

Open Workbook Using Name In Cell & Copy Data

Mar 16, 2008

I have a VBA-coded macro in an Excel workbook that is to open another existing workbook -- a .xls file, not .csv -- copy data from it, paste that into the original workbook where the macro resides, then close the source workbook.

If I use the debugger to step through the macro -- putting a breakpoint at its first executable line, run the macro, then F8 step through it, it works fine. (With delays at the open, close statements.) Free running, it doesn't. I suspect it's a timing issue, that the macro runs full tilt even though the new workbook isn't yet open -- but I don't know how to remedy that.

Here is the situation and the simplified code (the actual macro does a lot more, of course):

Main workbook: Two sheets, "Parameters" that has the fully-qualified filename for the desired source .xls in A1; and "Data", into which I want to paste data from that source.

Source workbook: Single sheet, "Sheet1"

Macro code. For simplicity, it is trying to copy/paste all of the source worksheet's content:

Sub Go()
' Go Macro
' Test of getting data from another spreadsheet
' Keyboard Shortcut: Ctrl+Shift+G
Dim SourceFile As String
Dim HomeBook As String
Dim OtherBook As String
SourceFile = Range("A1").Value
HomeBook = ActiveWorkbook.Name

right after the open, hoping that might cause a dwell for the open to complete.

When I step through it, the Locals view has all the parameters, getting set properly. If I try to simply run it, it stalls at the opened source workbook, the Locals view is empty, no data has been transferred into the initiating workbook.

If I place the breakpoint after the open, it is not reached. (I have the VBA open.) Hitting F8 then yields a VB error window, "Compile Error" "Expected: To"

View 3 Replies View Related

Macro Combines Data From Several Workbooks Into One Workbook

Apr 19, 2006

I have several individual excel workbooks all in one folder that I need to do some analysis on, but in order to that i need to have them all in one workbook. all of the files are saved in the same folder on my shared drive. each record from each of the files needs to be transfered over into this blank template that i have. I used the Blank template to create all of the individual files, Now i just need to get them all into one file that is easier to work with

View 9 Replies View Related

Macro To Copy Folders To Path Of Open Workbook Based On Cell Values

Aug 3, 2014

I have an Excel sheet that contains a few thousand folder paths in the first column. The first few cells in the column look similar to below.

C:UsersNameDesktopFolder Copy12010360
C:UsersNameDesktopFolder Copy12010361
C:UsersNameDesktopFolder Copy12010362
C:UsersNameDesktopFolder Copy12010363
C:UsersNameDesktopFolder Copy12010364
C:UsersNameDesktopFolder Copy12010365

I am trying to create a macro that will copy any folders that exist in any of the paths listed in the first column. The folders should be copied to the path of the open workbook containing the macro. Below is the macro I have currently, much of which was taken from information I found in this thread [URL]....


Sub wrapper3()
x = 1
Set fs = CreateObject("Scripting.FileSystemObject")
While Sheets("Air").Cells(x, 1) <> ""
v = InStrRev(Sheets("Air").Cells(x, 1), "")
dest = ActiveWorkbook.Path & Mid(Sheets("Air").Cells(x, 1), v, 99)


This code seems to work fine if all of the folders exist to be copied. My problem is that some do not and it is creating a "Path Not Found" error for which I need a fix. If the folder doesn't exist at the path nothing should be copied and the next path can be evaluated.

View 2 Replies View Related

Copy Data From Open File To Current Active Workbook

May 2, 2008

I want to create a standard macro that will copy values from a Master workbook to the current, active workbook I have open. The problem I have run into is when I record a macro it also records the name of the active workbook I'm copying data into and I would like it so when I bring up a workbook I just run the macro and it copies the values in. I'll be doing 8 different macros that each copy different values from the Master spreadsheet

View 8 Replies View Related

Workbooks.Open Does Not Activate The Workbook

Nov 5, 2008

I have a workbook containing macros that opens a second one (no macros) and does some 'data mining'.

The following VBA is used for that (I use this code on dozen of files and it has always worked, except here):

Set WshShell = CreateObject("WScript.Shell")
ChDir (WshShell.SpecialFolders("MyDocuments"))
BladNaam = Application.GetOpenFilename("Excel File, *.xls", , "Excel")
Workbooks.Open FileName:=BladNaam
TabNaam = ActiveSheet.Name

The problem is that most of the time the newly opened workbook is NOT activated (i.e put on top) and thus the rest of the code is executed on the wrong workbook...

If I put in a Msgbox(ActiveWorkbook.Name) 9 out of 10 times the active workbook is the initial one and not the one that was opened by the code.

tried replacing Active.Workbook with wb (dim wb as workbook).
tried to wait-a-few-seconds in between code
tried renaming

View 9 Replies View Related

Workbooks.Open Not Opening File Or Workbook

Oct 27, 2006

I was wondering if anybody could catch an error in the following code. I have a file, let's call it a "Guide" which is opened by user and at this time this file has only one purpose - to help user choose the program. After clicking on the "Choose Program" command button, an Inputbox appears where the user types in a program. Then the code should open the file with this program and this is pretty much it. But something is not working with the code below, and I do not see anything wrong with it after looking at it for so long. It just does not do antthing. how to handle the "Choosing" option

Private Sub CmdBttn_ChooseProgram_Click()
Dim sFilename As String
On Error Goto ErrorHandler
sFilename = "Approval_" & Application.InputBox("Input Program")
Workbooks.Open Filename:="C:Documents and SettingsjsmithDesktop" & sFilename & ".xls"
'if file name does not exist error message should display. Not defined yet
End Sub

View 3 Replies View Related

Copy Ranges Between Open Workbooks

May 14, 2008

I have several ranges (i.e. c11:c22, and d11:d22, etc) in an excel spreadsheet that, when the command button is selected, will copy these values into another already established workbook ("aggregator.xls").

Thus, the command button would have to pick each of these ranges and copy them into the aggregator workbook, (i.e. c11:c22 in the first workbook would be copied into b3:b14 in the aggregator workbook; d11:d22 would be copied into b18:b29 in the aggregator workbook, etc.)

In addition, I need it set up so that when the command button is selected to copy this data, that it will look in the aggregator workbook for the next available column for the section that the data will be copied to so that it doesn't write over the previous data.

View 6 Replies View Related

Open Multiple Workbooks & Copy Sheets

Jul 17, 2007

I have a created a main workbook with a macro that opens workbooks on a particular sheet from a list of workbook paths and filenames in the main workbook. The macro are suppose to copy the sheet and paste it into a sheet with a new name that I have defined from the list in the main workbook. I can get the macro to open the workbooks and close them. But I can't get the macro to copy the sheet into the main workbook.

I have attached the code and the workbook. I used slet_ark to delete previous sheet and hentark and henttekstfil to open the different workbooks.

The code I use are:

Public Sub Slet_ark()
Dim ark() As Variant
Dim Counter As Long
Dim FirstSheet As Long
Dim LastSheet As Long

View 3 Replies View Related

Enabling Manual Calculation On One Specific Workbook But All Other Open Workbooks Remain On

Mar 24, 2014

I want a specific workbook to be always on manual but when I open other workbooks I want them to remain on automatic even though the first workbook is set on manual through vba code. Is that possible to be done?

This is the code I run:

Private Sub Workbook_Activate()
With Application
.Calculation = xlManual
.MaxChange = 0.001
.CalculateBeforeSave = False

[Code] .....

I know that Application. Calculation refers to all open workbooks but I don't know the code to specify the manual calculation to this workbook only while others are open.

View 7 Replies View Related

Automatically Open, Copy, And Close Multiple Workbooks

Jul 26, 2006

I have 77 excel workbooks that are created each week, they are all in the same directory. I have to open each one and copy the data into a single workbook. The file names change slightly each week.

example: DIST_91124_GROWTH_PRODUCT XXX _07072006.xls The 07072006 is the week ending date and will change. Each of the 77 files has a different DIST_number.

Is there a way to automate this process, it takes me about 4 hours to do it manually.

View 9 Replies View Related

Copy Data From One Workbook To Updated Workbook Using Macro

May 1, 2012

I am creating a spreadsheet to provide to a group of about 40 people. The spreadsheet allows each member to track the referrals they receive and give. I need to plan on creating updates for the spreadsheet and want to make it so they can easily transfer their data to the most current version in the future. Here is a breakdown of the workbook:

Referrals Given
Referrals Received

I need to copy the data that they have input from the following worksheets:
Referrals Given
Referrals Received

Here is a breakdown of the "Referrals Received" worksheet:
A1:V4 - Data that will not change and includes many named cells
A5:Nxxx - Dynamic Named Range where they input their data
O5:Vxxx - Contains formulas

I need to be able to copy
from the old workbook to the new

Some side items to note:
There is VBA in the worksheet of
Private Sub Worksheet_Change(ByVal Target As Range)
and included in the code is an Unprotect & Protect code to always keep the sheet protected

I figure whatever works for this sheet will work for all the sheets.

View 1 Replies View Related

Create Open Copy Of Open Workbook

Jul 30, 2009

Create a full copy of an open workbook (eg. activeworkbook MyFile.xls) using VBA, with the new copy (eg Book1.xls) open as well ,without having to save a copy first then open it ?

View 9 Replies View Related

Copyrights 2005-15, All rights reserved