Bottom Line: Learn how to use VBA macros to copy & paste data from one Excel workbook to another, including adding data to the bottom of an existing range or replacing data.
Skill Level: Intermediate
Video Tutorial
Download the Excel Files
Follow along with the video above using the same Excel files that I use. You can download them by clicking below. Here's the workbook that I copy data from in my example:
Copy Data from One Workbook to Another Using Excel Macros
There are a few ways to copy & paste data with VBA. We are first going to use the Range.Copy method. This allows us to perform the entire action in one line of code.
Workbooks("New Data.xlsx").Worksheets("Export").Range("A2:D9").Copy _
Workbooks("Reports.xlsm").Worksheets("Data").Range("A2")
The Range.Copy method has an optional Destination parameter that allows us to specify the range we want to paste to.
We reference the source workbook, worksheet, and range that we want to copy from. For the Destination parameter we reference the destination workbook, worksheet, and the beginning cell of the range to paste to.
The Range.Copy method does a regular copy and paste that includes formatting and formulas. If you just want to paste values, there is an example below.
Important Points to Remember
When using this macro to copy data from one workbook to another, keep these points in mind.
- You must reference the correct file extension in the Workbooks property (see video above for details).
- Workbooks do not have to be macro enabled for this to work.
- This code can be stored in a separate workbook, such as your Personal Macro Workbook, if you choose. (Learn how to create a Personal Macro Workbook here.)
- You do not need to select or activate the workbooks, worksheets, or even ranges first. This is because the code already specifies those details.
- Both workbooks must be open when using this code. But the process of opening and closing workbooks can be automated with more code:
Sub OpenWorkbook()
'Open a workbook
'Open method requires full file path to be referenced.
Workbooks.Open "C:\Users\username\Documents\New Data.xlsx"
'Open method has additional parameters
'Workbooks.Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru, Local, CorruptLoad)
'Help page: https://docs.microsoft.com/en-us/office/vba/api/excel.workbooks.open
End Sub
Sub CloseWorkbook()
'Close a workbook
Workbooks("New Data.xlsx").Close SaveChanges:=True
'Close method has additional parameters
'Workbooks.Close(SaveChanges, Filename, RouteWorkbook)
'Help page: https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.close
End Sub
PasteSpecial Method to Paste Values, Formats, etc.
When pasting data into the destination workbook using VBA, you can also use any of the normal Paste Special features.
There is an example macro below. You'll notice that my example uses the PasteValues type, but you could also use PasteFormulas, PasteFormats, or any of the other PasteSpecial options available. Here is a list of the PasteTypes.
'Copy range to clipboard
Workbooks("New Data.xlsx").Worksheets("Export").Range("A2:D9").Copy
'PasteSpecial to paste values, formulas, formats, etc.
Workbooks("Reports.xlsm").Worksheets("Data").Range("A2").PasteSpecial Paste:=xlPasteValues
To learn more about PasteSpecial options, check out my video series on Copy and Paste with VBA.
Pasting Below the Last Cell
Sometimes the size of your data ranges in the source and destination files will change every time you run the macro. For example, you may have a daily task of adding new entries from an exported sheet to a master list in another workbook.
In that case, you'll want to add the new entries directly below the last entry on your destination sheet. To do that, you can use the following macro.
Sub Copy_Paste_Below_Last_Cell()
'Find the last used row in both sheets and copy and paste data below existing data.
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
'Set variables for copy and destination sheets
Set wsCopy = Workbooks("New Data.xlsx").Worksheets("Export 2")
Set wsDest = Workbooks("Reports.xlsm").Worksheets("All Data")
'1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
'2. Find first blank row in the destination range based on data in column A
'Offset property moves down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
'3. Copy & Paste Data
wsCopy.Range("A2:D" & lCopyLastRow).Copy _
wsDest.Range("A" & lDestLastRow)
This code pastes your source data just below the existing destination sheet data.
In addition to finding the last row in a range or sheet, you can find the last column or cell as well. Checkout my post and video on 3 ways to find the last used row or column to learn more.
Clearing the Destination Range Before Pasting
Instead of adding to a list in your destination range, you may prefer to clear the existing range before pasting the new data. You can do that with this macro.
Sub Clear_Existing_Data_Before_Paste()
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
Set wsCopy = Workbooks("New Data.xlsx").Worksheets("Export 2")
Set wsDest = Workbooks("Reports.xlsm").Worksheets("All Data")
'1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
'2. Find first blank row in the destination range based on data in column A
'Offset property moves down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
'3. Clear contents of existing data range
wsDest.Range("A2:D" & lDestLastRow).ClearContents
'4. Copy & Paste Data
wsCopy.Range("A2:D" & lCopyLastRow).Copy _
wsDest.Range("A2")
End Sub
Running that macro will remove any existing data in the destination range before inserting the data from the source worksheet.
Alternative Code for Copying Data to Your Current Workbook
I wanted to also present to you a slightly different option for your macro. Instead of identifying the destination workbook by name, you can use the ThisWorkbook property. This can be done as long as the macro is stored in the destination (or source) workbook.
By doing this, you avoid having to change the code in the event you change the file name for your destination workbook. Here is the VBA code that uses ThisWorkbook.
Workbooks("New Data.xlsx").Worksheets("Export").Range("A2:D9").Copy _
ThisWorkbook.Worksheets("Data").Range("A2")
This reminds me that VBA will always assume that the macro you want to run applies to the active workbook if you don't specify a workbook in each line of code. I talk about that critical assumption and other important points about running VBA code in this video on VBA Assumptions.
Copy Paste Between Sheets in Same Workbook
You can modify any of the examples above to copy & paste between sheets in the same workbook. Just use the same workbook reference for the copy and destination ranges. Here is an example.
'Copy range to clipboard
Workbooks("New Data.xlsx").Worksheets("Export").Range("A2:D9").Copy
'PasteSpecial to paste values, formulas, formats, etc.
Workbooks("New Data.xlsm").Worksheets("Data").Range("A2").PasteSpecial Paste:=xlPasteValues
You won't always need to specify the workbook, but it is a good habit to get into. Otherwise, VBA makes assumptions that can get you in trouble.
Conclusion
I hope these tips and macros help save you time when copying data between workbooks. Automating this boring task will help prevent errors and make it easy for others to update your reports.
Please leave a comment below with any questions or suggestions. Thank you! 🙂
Thanks for this wonderful tutorial.
For Pasting Below the Last Cell, can i have the code for copy pasting just the values as the code mentioned above copy pastes with the formula
Hi,
Thank you so much for the above code. I got it all working in 2 new workbooks that I created, but when I tried to add the code to an existing workbook then it is highlighting the first Sub line and I get the error Compile Error: Expected Identifier.
Do you know what I´ve done wrong?
Many thanks
Hi
Can specific columns be moved without running the workbook being transferred to?
Hi Jon and congratulations for the post. It’s clear and straight to the point.
One minor question: how should I modify the subs in case I needed to copy only the rows where one specific cell is empty?
Let me rephrase. One of the cells is a toggle field (“OK” = done, empty = yet to be done). I just want to copy the rows where the toggle is empty. Again, thank you for the post.
I have interfaced to many tutorials .. and yours is the best I have used in over 15 years .. well done .. (can I clone you 🙂 )
Hi, I am new to VBA and would like your help to update below code to paste values and formats ?
Sub Copy_Paste_Below_Last_Cell()
‘Find the last used row in both sheets and copy and paste data below existing data.
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
‘Set variables for copy and destination sheets
Set wsCopy = Workbooks(“New-Data.xlsx”).Worksheets(“Export 2”)
Set wsDest = Workbooks(“Reports.xlsm”).Worksheets(“All Data”)
‘1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, “A”).End(xlUp).Row
‘2. Find first blank row in the destination range based on data in column A
‘Offset property moves down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, “A”).End(xlUp).Offset(1).Row
‘3. Copy & Paste Data
wsCopy.Range(“A2:D” & lCopyLastRow).Copy _
wsDest.Range(“A” & lDestLastRow)
End Sub
yes it works but I want to copy Table with same property like bold font, border, thick border
Hi this is an excellent VBA,
I have one query though, I’m trying to use this code to copy data from a worksheet that has data validation and conditional formatting in it. When I run it, the code also copies and pastes all data including validation and formatting to the destination worksheet. However, I would like to be able to copy data and paste it as VALUES ONLY, without the conditional formatting as well as the validation from the source worksheet.
Now, how should I end or replace this string:
wsCopy.Range(“A2:D” & lCopyLastRow).Copy _
wsDest.Range(“A2”)
so that I am copying and pasting unformatted values only from source sheet to destination sheet.
When I use your code for pasting the data:
Workbooks(“WorkbookName”).Worksheets(“WorksheetName”).Range(“D3”).PasteSpecial Paste:=xlPasteValues
‘Sheets(“Menu”).Activate
I receive an error message:
“Run-time error ‘9:
Subscript out of range”
how do I auto run this. I want it in such a way that the minute I open the WB, the macros should run
but it doesnt.
Using you “pat below the last cell”. How can I get it to “PastSpecial Past:=xlPastValues”. I need it to past only the result of the formula.
Thank you for the great video. Would you happen to have a video on how to move data from one workbook to another based on a certain criteria & only if the data does not already exist in the destination workbook?
For example, I open a newly exported report every morning, (approximately 3k rows) & place a filter on it & in column D, I have 16 unique values. All of the rows have to be moved to their own workbook based on the value in column d. (So 16 different workbooks) but I don’t want to transfer the rows if they already exist.
Any advice on this would be greatly appreciated. Thank you!
Jon – quick question – I’m following the instructions for “PAste below the last cell”, but I need the data to pasted as values only. However, when I try to add a “Pastespecial” instruction to the end of the code above it bugs out. What am I doing wrong?
I’m having the same problem….
Hi,
Really thanks for the sharing this helpful tips in copy & paste in excel.
By now, I am trying to edit the code to copy the selected range and paste it on another workbook for record purpose with pastespecial.value since I am copying the data from difference excel which start from difference row. Is it a way for me to edit the code to able me select the range to copy every time I’m running macro rather then go into the macro page to edit the code every time before I start to copy?
Great code – thanks
How can the cells to be copied containing an IF formula (where the false value = “”) be copied to the new worksheet without leaving a cell which appears blank but has an empty string showing. This means that the code looks for the last blank line but passes over the ‘blank’ cells as they are not truely blank
Thank you for your formula “Pasting Below the Last Cell;” it is exactly what I was looking for. One note, you left off “End Sub” in the formula.
Can we merge all these codes in single module…
Hi Jon,
Very Helpfull your code, could you please tell me how to paste the data while skiping the header row.
Exactly what I am searching for these vba codes, thanks a lot!!
Hi, it only works if the source sheet is open, how can we make it work without the source sheet being open??
Hi, with ADO can be done without opening file.
Hi, I am new in macros and I have been trying to do this but no luck. Could you please help me.
I have a workbook with my macros in it (WB1). I want to copy a cell from workbook2 (WB2) to WB1 column A. I want to sum up column c,d,e of WB2 and put the result to WB1 column B. Then I do the next row of WB2 and put the result to the next row of WB1. I want this process in a loop until I copied all of WB2.
Thank you
Jon,
Thanks for this. I do have a quick question. I am trying to add index & Match Data from one table and pasting as values to the bottom of another table. The following code works but it’s pasting the formulas…
‘3. Copy & Paste Data
wsCopy.Range(“B9:H” & lCopyLastRow).Copy _
wsDest.Range(“A” & lDestLastRow)
I have been trying to modify to pastespecial but it keeps giving me errors. The following isn’t working.
‘3. Copy & Paste Data
wsCopy.Range(“B9:H” & lCopyLastRow).Copy _
wsDest.Range(“A” & lDestLastRow).PasteSpecial
Paste:=xlPasteValues
It is giving a compile error, expected end of statement.
Hello! How about if i want to copy paste from one workbook to another repeatedly? Like:
sheet1 to another workbook sheet1
sheet2- sheet2
sheet3 – sheet3 etc.
thanks!
Hi Jon,
I used your “Pasting Below the Last Cell” code and work perfectly but I want to paste value only and I dont know which script I need to add .value or .pastespecial xlpastevalues.
Thanks
I have a problem with this code. Can u help me?
This was great info thank you. I am new to vba so I have a question regarding how to combine the copy/ paste code and the paste special function. I am trying to combine the ‘pasting below the last row’ code and the paste special function.
I have a table that I am copying to a new workbook, as I update the table, I am copying the new table below the previously pasted table. This seems to be working but I need to paste the values as I am getting #ref! In some of the cells in the pasted table.
I have tried various combinations of code but haven’t been successful.
Any help with code would be greatly appreciated.
Thanks in advance.
Hi,
Thank you for all the explanations.
I have actually 1 question. So I am trying to Copy-Paste from one workbook to another “Pasting Below the Last Cell” method, but I would like to compile this one with the “Application.GetOpenFilename” so that in the end the user can open and browse the local machine for the needed file and paste automatically below the last cell.
I have this code:
Sub Get_Data_From_File()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:=”Browse for your File”, FileFilter:=”Excel Files(*xlsx*),*xlsx*”)
If FileToOpen False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range(“A1:AH1000000”).Copy
ThisWorkbook.Worksheets(“OrderStatus”).Range(“A1”).PasteSpecial xlPasteAll
End If
Application.ScreenUpdating = True
End Sub
Thank you,
Adrian
Hi Jon,
Thanks for the tips. how can I use them with data that includes a column of cells with sequential data to be used as a pull dowm list on a form?
Hi ,
I need copy and paste in same sheet…
That is …like this
ColumnA Column B
Test1 TestA
Test1 Test B
Test 2 Testc
I want it to be
Column C Column D
Test1(header) Test2(Header)
TestA TestC
TestB
Help please
getting Runtime error 9 subscript out of range (dont know VBA)
Sub copydata()
Workbooks(“PO2.xlsx”).Worksheets(“POR”).Range(“B5:B14”).Copy _
Workbooks(“data_po_1.xlsx”).Worksheets(“Data”).Range(“A2”)
End Sub
Hi, how do I edit if my work book source data name always changes as its just a temp file exported from accountancy package?
So the “New Data” bit cahnages to diff tmp temp file names.
Set wsCopy = Workbooks(“New Data.xlsx”)
Thanks
Hey there I have a question;
I have 10 workbooks and a master one, I want to reference every same cell in other workbooks to the master one using this;
='[1003.xlsx]OCT”21′!$AE$16
but the thing is can i make that “1003” from a cell in master file??
I think I’m just getting confused by all the various options. I simply want to run a macro that will copy the last cell of column A and paste it into the next blank cell in column A. Worksheet name is “Shares Data”, and Column A is part of a table. Thanks for simple help.
What if the name of the worksheet that I want to copy data from changes on a daily basis, how can I account for that in my VBA?
Thanks for your help.
I would change the name to a date and use a generic “DATE” as a variable so it will use today’s date.
Hi,
I can not export data if the another workbook is already opened. please suggest a code that can paste data even the destination workbook is already opened.
hello Im getting 0 for both lCopylastrow and lDestLastrow even though i copy and paste the code into the macro, also im working off two tutorial because i need to be able to open any file and paste the data into “thisworkbook”
what if the range is different each time?
if i snd you a couple of files are you able to help please?
Hi Jon,
I was wondering if a variation of what you have done here is possible. I receive directory updates via email from various agencies. Is there anyway that when I open the spreadsheet I receive I can run a macro that can copy particular data ranges from specific columns from that spreadsheet and paste them into specific columns in a different spreadsheet below the last filled cell.
For example, the emailed spreadsheet of directory updates has data in C3:C15, D3:D15, F3:F15 nd H3:H15 that I need to copy to my existing directory where the majority of the data goes into the matching column however H data would need to go into column M.
Any assistance you can provide would be fantastic.
I need a help, the above copy method VBA is what i am looking for but I need the destination workbook and worksheet as variable and the value will be taken from the cell value of copy worksheet.
example: My active worksheet is named DATA ENTRY. in this, a cell G11 is a worksheet name of another workbook. that workbook name is in G10. I need to copy G9 value to G11worksheet in the last row.
I know this is little bit confusing.
in simple way, to this below code I need varying workbook name and worksheet names ( which are taken from cell values)
Workbooks(“New Data.xlsm”).Worksheets(“Data”).Range(“A2”).PasteSpecial Paste:=xlPasteValues
Any help will be appreciated..
Great examps, but none show how to code it IN the source wkbk & send it TO another, & I find no combo of your suggestions that work; get subscript out of range no matter how I try.
Workbooks.Open “E:POS2INVInvSys.xlsm”
Workbooks(“POS2INV”).Worksheets(“pivot”).Range(“A1:L485”).Copy_ ‘err:subscr outofrng (on copy part)
Workbooks(“InvSys”).Worksheets(“Sheet1”).Range (“A1”)
Workbooks(“InvSys”).Close SaveChanges = True
(open & close work, but not copy)
Great examps, but none show how to code it IN the source wkbk & send it TO another, & I find no combo of your suggestions that work; get subscript out of range no matter how I try.
Workbooks.Open “E:POS2INVInvSys.xlsm”
Workbooks(“POS2INV”).Worksheets(“pivot”).Range(“A1:L485”).Copy_ ‘err:subscr outofrng (on copy part)
Workbooks(“InvSys”).Worksheets(“Sheet1”).Range (“A1”)
Workbooks(“InvSys”).Close SaveChanges = True
(open & close work, but not copy)
How would one go about a cell with a defined name (ie. “Projectname”) instead of a cell (ie. A1)?
HI, I have an excel work book contains of 3 (THREE) excel sheet named as.
1)ITEM LIST Sheet
(in there FOUR columns used as named SR.NO, ITEM CODE, ITEM NAME and SALES PRICE. TWO Columns named ITEM CODE and ITEM NAME should be non-editable)
2)ITEM RECEIVED Sheet
(in there EIGHT columns used as named DATE, INVOICE NO, SUPPLIER NAME, ITEM CODE, ITEM NAME, ITEM QUANTITY, UNIT PRICE, INVOICE VALUE)
3)SUPPLIER LIST Sheet
(in there FIVE columns used as named DATE, INVOICE NO, SUPPLIER NAME, ITEM NAME, INVOICE VALUE. Used Columns also should be non-editable)
I have entered data to at ‘ITEM RECEIVED’ Sheet as per criteria. Now I want to transfer Scheduled Data such as cell data of “D5”,”H5”,” L5”,” P5” as ‘ITEM CODE’ and “E5”,” I5”,” M5”,” Q5” as ‘ITEM NAME’ From ‘ITEM RECEIVED’ Sheet to Cell “B3” as ‘ITEM CODE ‘and to Cell “C3” as ‘ITEM NAME’ to ‘ITEM LIST’ Sheet. Again I also want to transfer Scheduled Data such as cell data of “A5”,” B5”,” C5”, as ‘DATE’,’INVOICE’, ‘SUPPLIER NAME’,“E5”,” I5”,” M5”,” Q5” as ‘ITEM NAME’, “F5”,” J5”,” N5”,” R5” as ‘QTY’ and “X5” as ‘INVOICE VALUE’ From ‘ITEM RECEIVED’ Sheet to “B3”,”C3”, “D3” as ‘DATE’,’INVOICE’, ‘SUPPLIER NAME’, “E3”,”G3”, “I3”,”K3”,‘ITEM NAME‘ and to “F3”,”H3”, “J3”,”L3” as ‘QTY’ of ‘SUPPLIER LIST’ Sheet by pressing existing ‘SAVE’ Button in ‘ITEM RECEIVED’ Sheet by using VBA Code each time after completing task in ‘ITEM RECEIVED’ Sheet and it will be occurred as same frequently after every completing task. While enter I enter data in ‘ITEM RECEIVED’ Sheet, if there is found “ITEM CODE’ and ‘ITEM NAME’ are same then there should be no change. May I get help in this regards
HI, I have an excel work book contains of 3 (THREE) excel sheet named as.
1)ITEM LIST Sheet
(in there FOUR columns used as named SR.NO, ITEM CODE, ITEM NAME and SALES PRICE. TWO Columns named ITEM CODE and ITEM NAME should be non-editable)
2)ITEM RECEIVED Sheet
(in there EIGHT columns used as named DATE, INVOICE NO, SUPPLIER NAME, ITEM CODE, ITEM NAME, ITEM QUANTITY, UNIT PRICE, INVOICE VALUE)
3)SUPPLIER LIST Sheet
(in there FIVE columns used as named DATE, INVOICE NO, SUPPLIER NAME, ITEM NAME, INVOICE VALUE. Used Columns also should be non-editable)
I have entered data to at ‘ITEM RECEIVED’ Sheet as per criteria. Now I want to transfer Scheduled Data such as cell data of “D5”,”H5”,” L5”,” P5” as ‘ITEM CODE’ and “E5”,” I5”,” M5”,” Q5” as ‘ITEM NAME’ From ‘ITEM RECEIVED’ Sheet to Cell “B3” as ‘ITEM CODE ‘and to Cell “C3” as ‘ITEM NAME’ to ‘ITEM LIST’ Sheet. Simultaneously at once I also want to transfer Scheduled Data such as cell data of “A5”,” B5”,” C5”, as ‘DATE’,’INVOICE’, ‘SUPPLIER NAME’,“E5”,” I5”,” M5”,” Q5” as ‘ITEM NAME’, “F5”,” J5”,” N5”,” R5” as ‘QTY’ and “X5” as ‘INVOICE VALUE’ From ‘ITEM RECEIVED’ Sheet to “B3”,”C3”, “D3” as ‘DATE’,’INVOICE’, ‘SUPPLIER NAME’, “E3”,”G3”, “I3”,”K3”,‘ITEM NAME‘ and to “F3”,”H3”, “J3”,”L3” as ‘QTY’ of ‘SUPPLIER LIST’ Sheet by pressing existing ‘SAVE’ Button in ‘ITEM RECEIVED’ Sheet by using VBA Code for each time after completing every received task in ‘ITEM RECEIVED’ Sheet and it will be occurred as same frequently in next row of both ‘ITEM LIST’ and ‘SUPPLIER LIST’ Sheet. While I enter data in ‘ITEM RECEIVED’ Sheet, if there is found “ITEM CODE’ and ‘ITEM NAME’ are same then there should not be RE-PASTE. Being new to VBA looking for VBA Code in this regards
HI, I have an excel work book contains of 3 (THREE) excel sheet named as.
1)ITEM LIST Sheet
(in there FOUR columns used as named SR.NO, ITEM CODE, ITEM NAME and SALES PRICE. TWO Columns named ITEM CODE and ITEM NAME should be non-editable)
2)ITEM RECEIVED Sheet
(in there EIGHT columns used as named DATE, INVOICE NO, SUPPLIER NAME, ITEM CODE, ITEM NAME, ITEM QUANTITY, UNIT PRICE, INVOICE VALUE)
3)SUPPLIER LIST Sheet
(in there FIVE columns used as named DATE, INVOICE NO, SUPPLIER NAME, ITEM NAME, INVOICE VALUE. Used Columns also should be non-editable)
I have entered data to at ‘ITEM RECEIVED’ Sheet as per criteria. Now I want to transfer Scheduled Data such as cell data of “D5”,”H5”,” L5”,” P5” as ‘ITEM CODE’ and “E5”,” I5”,” M5”,” Q5” as ‘ITEM NAME’ From ‘ITEM RECEIVED’ Sheet to Cell “B3” as ‘ITEM CODE ‘and to Cell “C3” as ‘ITEM NAME’ to ‘ITEM LIST’ Sheet. Simultaneously at once I also want to transfer Scheduled Data such as cell data of “A5”,” B5”,” C5”, as ‘DATE’,’INVOICE’, ‘SUPPLIER NAME’,“E5”,” I5”,” M5”,” Q5” as ‘ITEM NAME’, “F5”,” J5”,” N5”,” R5” as ‘QTY’ and “X5” as ‘INVOICE VALUE’ From ‘ITEM RECEIVED’ Sheet to “B3”,”C3”, “D3” as ‘DATE’,’INVOICE’, ‘SUPPLIER NAME’, “E3”,”G3”, “I3”,”K3”,‘ITEM NAME‘ and to “F3”,”H3”, “J3”,”L3” as ‘QTY’ of ‘SUPPLIER LIST’ Sheet by pressing existing ‘SAVE’ Button in ‘ITEM RECEIVED’ Sheet by using VBA Code for each time after completing every received task in ‘ITEM RECEIVED’ Sheet and it will be occurred as same frequently in next row of both ‘ITEM LIST’ and ‘SUPPLIER LIST’ Sheet. While I enter data in ‘ITEM RECEIVED’ Sheet, if there is found “ITEM CODE’ and ‘ITEM NAME’ are same in ‘ITEM LIST’ Sheet then there should not be RE-PASTE. Being new to VBA looking for VBA Code in this regards
Workbooks(RollID).Worksheets(“Sheet1”).Range(MyStop).Copy Workbooks(MyFn).Worksheets(“sf_processed”).Range(“K” & i) —is my formula.
MyStop contains the value of what I want to copy and “K” & i has i as 5 to the number of records in the file (so, it would be 5 as in K5 the first time through my code). This does NOT work but the following does. Why can’t I have a variable in place of “C20007” and a variable such as “i” rather than “K5”?
Workbooks(RollID).Worksheets(“Sheet1”).Range(“C20007”).Copy Workbooks(MyFn).Worksheets(“sf_processed”).Range(“K5”)
Thank You [email protected] for Your Trying help me. but i need DATA Transfer from a particular Spreadsheet to TWO Spreadsheet in a same Workbook at a time after pressing SAVE Button in particular Spreadsheet from where the DATA will be transferred.
These steps worked well for me. I work remotely with a pretty crappy VPN. I found what worked best for me (open file, copy file data, close file). Also, my excel was freezing and not responding and then crashing a few times so I ran through these 6 tricks to fix excel 2016 freezing (https://www.repairmsexcel.com/blog/excel-hangs-when-copy-pasting). Thanks for the posts they were helpful.
Oh, P.S. I ran all the code from a “workbook open event.” It makes it easier than placing a button or waiting for the user to remember to click on a button.
This is really a great tutorial and got me started on VBA. However, would be useful if the case where the target workbook did not exist, and there is a need create one.
Hi It’s fantastic
One small problem New-Data.zip contains an .xls file and not a macro enabled file. Please help
Thanks
Leon