Excel VBA To Copy Data From One Sheet To Another (BEGINNER TO PRO!)

  Рет қаралды 97,326

Tiger Spreadsheet Solutions

Tiger Spreadsheet Solutions

3 жыл бұрын

How much time do you spend copying data from one sheet to another in Excel? It’s annoying, time-consuming … and prone to human error. It leaves you thinking: “there must be a better way …”
The good news: copying data in Excel from one sheet to another is what VBA absolutely loves! Even beginners can harness VBA to start moving data round.
In this video, I show you how to do this task at 5 levels of sophistication: from a simple one-line macro that an Excel beginner can use, to the actual mechanism I use on my projects to copy data from one sheet to another with Excel VBA. Are you ready to automate that time-consuming task? Let’s do this!
💻Download File Link
tinyurl.com/59sudyub
💼Tiger Excel Basics - Rebuild Your Excel Foundation
www.tigerspreadsheetsolutions...
1. Basic A = B Operation
Let’s start with a basic A=B operation to get data moving around Excel using Excel VBA. The trick here is to remember which of A or B is the ‘destination’ (where the data ends up), and which is the ‘origin’ (where the data starts).
A (Destination) = B (Origin)
In this beginner Excel VBA construct, A is the destination and B the origin.
To translate this into Excel VBA:
Range(“B1”).value = Range(“A1”).value
copies the data from cell A1 into cell B1.
Next, try ‘stacking up’ multiple lines of code to perform multiple data transfer operations. All lines of code are executed as part of the same macro. Cool!
2. Basic A = B Operation Across Sheets
A small additional piece of code allows us to copy data between sheets. It’s as easy as:
Sheets(“Template”).Range(“D1”).value = _
Sheets(“Data”).Range(“A1”).value
Once again, try creating multiple lines of code to make the VBA routine even more useful. Note there is quite a lot of code accumulating in the VBA editor, now. Hhhmm …
Are you ready for a big step up in terms of difficulty … and power? I am going to introduce you to the actual mechanism I use to copy data from one sheet to another with Excel VBA. Let’s do this …
3. It would be perfect if we could control the data transfer … from a worksheet. That would avoid going into the VBA editor all the time and would make it easy to tweak or add to the data transfer.
We can do this with a table in the spreadsheet and a few supremely powerful lines of Excel VBA code.
Go ahead and create the 2-column table, or adapt the example in the download file.
Next: the supremely powerful line of Excel VBA code.
Warning: it’s a bit mind-bending! But the flexibility it creates is just awesome …
Range(Range(“C4”).Value).value = Range(Range(“C5”).value).value
Woah! What happened there?!
By embedding another cell reference within the usual Range(cell_address).value construct, we get Excel to read a cell input as a cell address. In other words, we control the origin and destination cells with cell inputs. Oh, yes! Punch the air …
By adding the sheet references, we can instantly copy data from one sheet to another using Excel VBA. And the process is controlled with worksheet cell inputs. Yes!
Sheets(“Template”).Range(Range(“G4”).Value).value = _
Sheets(“Data”).Range(Range(“H4”).Value).value
💼Tiger Excel Basics - Rebuild Your Excel Foundation
www.tigerspreadsheetsolutions...
4. Loop through the table
A loop allows us to do this with minimal additional code. Let’s use a ‘For Each’ loop to tell Excel to do something to each cell in the data transfer table, and use the .offset method to reference the cell to the right of the column we are looping through.
Dim Chris_Cell As Range
For Each Chris_Cell In Range(“G5:G7”)
Sheets(“Template”).Range(Chris_Cell.value).value = _
Sheets(“Data”).Range(Chris_Cell.offset(0,1).value).value
Next Chris_Cell
I’m counting 1,2,3 .. 4 lines of code. Yes, just four lines of code to transfer data from one sheet to another with Excel VBA. Why did I not try VBA earlier? I know!
5. Make the code dynamic (new entries)
Now, let’s take this solution to professional level. Things change in business, so an Excel VBA application should have the flexibility to respond to changes. Formulae and VBA should not be ‘hard-coded’; rather, we should aim for a ‘dynamic’ approach that can be quickly tweaked WITHOUT having to edit formulae or access the VBA editor.
It is possible with some advanced VBA. Hold tight!
Dim Chris_Cell As Range
For Each Chris_Cell In Range(Range(“G5”),Range(“G5”).end(xldown))
Sheets(“Template”).Range(Chris_Cell.value).value _
Sheets(“Data”).Range(Chris_Cell.offset(0,1).value).value
Next Chris_Cell
The result? A powerful, flexible, professional-level Excel VBA mechanism to copy data from one sheet to another in Excel.
💼Tiger Excel Basics - Rebuild Your Excel Foundation
www.tigerspreadsheetsolutions...

Пікірлер: 59
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 3 жыл бұрын
🔥WATCH NEXT: The Future Of Excel VBA? kzfaq.info/get/bejne/kJxirLKDzbbWY4U.html
@sbatsia
@sbatsia 3 жыл бұрын
Further to my recent email, this direct transfer method has been demonstrated and explained in a noticeably clear and comprehensible way. I'm happy to express my thanks and appreciation to you!
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 3 жыл бұрын
You're welcome, Shlomo!
@ngee4925
@ngee4925 3 жыл бұрын
I really love all of your VBA videos, always super helpful, thank you!
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 3 жыл бұрын
Thank you my friend and welcome to the channel!
@ngee4925
@ngee4925 3 жыл бұрын
Thank you! I’m glad to be a subscriber!
@steveknapp244
@steveknapp244 3 жыл бұрын
Advanced Autofilter via vba is by far the fastest way to move data between sheets. I tested copy and paste vs AAF, and the time difference was literally less than half the time. Good, clear content as always 👍 I see you have succumbed to the lock down trim....I’ve had a wife trim very similar 🤣
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 3 жыл бұрын
Copying is slow ... but this video actually covers direct transfer, not copy, the reference to 'copy' is just to bring the punters in. Oh, and a picture of the lockdown cut is required!
@ramandeepsingh8110
@ramandeepsingh8110 2 жыл бұрын
You are superb Brother! I have seen all of your videos and made my notes which helped me a lot with my daily tasks. Thanks! Lots of Love & Wishes from India!
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 2 жыл бұрын
That's very kind of you my friend, keep enjoying the videos!
@tlee7028
@tlee7028 3 жыл бұрын
This is clearly explained ! 👍
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 3 жыл бұрын
Thank you! I enjoyed putting this one together ...
@gaspumprepairservice7009
@gaspumprepairservice7009 6 ай бұрын
Good information, thx. I’m learning VBA at 60-something and your presentation is easily digestible.
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 6 ай бұрын
Welcome to the community - do take a look at our other videos on VBA
@bartverheyden8851
@bartverheyden8851 3 жыл бұрын
VBA makes this so easy! Really nice topic
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 3 жыл бұрын
Thanks Bart, I agree!
@kralios
@kralios 8 ай бұрын
very helpfull video, thank you
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 8 ай бұрын
It's a pleasure - see you in another video on the channel!
@Jojosmith342
@Jojosmith342 Жыл бұрын
Thank you very much Chris for your great lesson. I have been searching for days fortunately I've found you the Super great teacher for VBA Excel. Thanks millions. Subscribed, definately liked! Looking forward to more lessons
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions Жыл бұрын
Fantastic to hear Tammy, welcome to the community! We have many VBA videos you'll like ...
@Jojosmith342
@Jojosmith342 Жыл бұрын
@@TigerSpreadsheetSolutions Yes, I did bookmark your website as well. There was a developed data entry macro excel form that hide all the sheets. I am trying to find the way how to collect all data from 60 fields into master sheet. I dont know if I can use your method 5.
@Jojosmith342
@Jojosmith342 Жыл бұрын
@@TigerSpreadsheetSolutions thank you very much for your quick reply Chris. I tried method one to extract data from data entry excel form and received the run-time error'1004': application-defined or object-defined error. I created 2 sheets data, template as yours and copied your code of method 5. I also create the origin and destination cells but dont know why it does not work for me
@Jojosmith342
@Jojosmith342 Жыл бұрын
@@TigerSpreadsheetSolutions Hi Chris, I just tried Method 2 seems working but not dynamic.
@wrlomprez3802
@wrlomprez3802 Жыл бұрын
Thanks a lot, I needed this moving a ton of data around this cut time down to nothing damn
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions Жыл бұрын
Great to hear - that's the power of VBA!
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 3 жыл бұрын
Which method are you using to copy data from one sheet to another with Excel VBA - 1,2,3,4 ... or 5? Let me know in the comments, I will get back to you ..👇
@mcinik1
@mcinik1 3 жыл бұрын
I'm still copy and pasting this should save me hours thanks Chris
@tracycritchley8564
@tracycritchley8564 3 жыл бұрын
I would like to use Method 5 to move the last piece of data added to one sheet and automatically move to another sheet. In the VBA lessons you did we did a "List" tab. I would like to add the data to this worksheet. However, I am getting Error- Run-time1004 Application-defined or object -define error. I am getting this same error on Methods 3 thru Method 5. If there is a way to help, that would be much appreciated!
@MrEliseo0808
@MrEliseo0808 Жыл бұрын
Same here
@user-kn2uo5qx5p
@user-kn2uo5qx5p 8 ай бұрын
Here as well.
@stevennye2441
@stevennye2441 2 жыл бұрын
Excellent work, I started off thinking what is he doing? but your code ended up with a much cleaner solution than I expected.
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 2 жыл бұрын
Thanks Steven - love this comment, I like to hold you in suspense as long as possible :-)
@abosjolh596
@abosjolh596 Жыл бұрын
simply you are magic
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions Жыл бұрын
Thank you my friend - I'm happy you enjoyed this one!
@amarbirajdar7243
@amarbirajdar7243 11 ай бұрын
Hey Chris, So what if I have to create a new sheet on daily basis with date as the name of sheet and I have to copy the headers from the previous sheet. I know I have might have to use a variable for the sheet names but I am unable to find some example around it to get a reference. I have created a vba code to create new sheet and change its name to date but unable to proceed further. Can you help me here?
@martinshaw254
@martinshaw254 3 ай бұрын
How could you change this to copy a formula instead of just a value? Is it possible
@rudolfnel5934
@rudolfnel5934 2 жыл бұрын
great video i however need to copy over complete columns do you have a video with an example script of that
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions Жыл бұрын
Hi Rudolf, thanks - I don't recommend copying complete columns because it's resource-intensive. But, I'm sure you can use and internet search to find the required VBA ... good luck!
@pradeepprabhui6662
@pradeepprabhui6662 2 жыл бұрын
Hi there, thanks a lot for this video.. Very informative i must say.. I do a lot of copy pasting from one workbook to another Condition - the cell that i will be copying from one workbook to another should happen only when a value matches.. (match function) How can i do this? Need your valuable assistance
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions Жыл бұрын
Hi Pradeep - you'd have to combine the techniques taught in this video with others such as conditional statements. I would recommend one of our longer VBA learning series to get to grips with the skills. Good luck!
@NethaLawrence
@NethaLawrence 5 ай бұрын
This Video is great. One question though how can you have the code work without always clicking the play button? So when you type the value in one cell it auto copies it to another.
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 5 ай бұрын
Hi there - thank you! It's possible to get a macro to run when a value changes in a cell using what are called workbook event triggered macros. I don't recommend these however, because you very quickly feel like you've lost control with macros being triggered in the background constantly. That's why I recommend using buttons to trigger macros.
@Luigi0228
@Luigi0228 2 жыл бұрын
Great video Chris, thank you very much. I have downloaded your file for the link provided and when I run the "Use_Table_To_Copy_Data() routine" and I get a "Run-time error ‘1004’: Application-defined or object-defined error". I haven't changed anything in your code. Are there any settings that I have to perhaps change on my side?
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 2 жыл бұрын
Hi Luigi - I think there's actually a mistake in the download file. Change G4 to G5 and H4 to H5 in that macro and things should work.
@Luigi0228
@Luigi0228 2 жыл бұрын
@@TigerSpreadsheetSolutions Thanks Chris, all working now.
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 2 жыл бұрын
Luigi Liccardo thanks for pointing it out
@hastyscorpion
@hastyscorpion 3 жыл бұрын
I am slightly confused by 6:55. Since you changed the Origin to the Data sheet, why isn't the origin pulling the address from H5 on the Data sheet? Is it because range.value function only pulls from the active sheet?
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 3 жыл бұрын
It's a difficult one to explain. I would recommend dowloading the file and practising yourself. Good luck!
@brianbarns8675
@brianbarns8675 Ай бұрын
Hey Chris, This is interesting but what if I want this to work on auto so when data is entered in the 1st sheet it will also appear in the destination sheet with using a play or activate button. The next step would be to sort the data on the destination sheet and only show the top ranking results with the code running on auto. Is there a more detailed video on your website?
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions Ай бұрын
What do you mean by 'in auto'? You want it to run without clicking a button?
@brianbarns8675
@brianbarns8675 Ай бұрын
@@TigerSpreadsheetSolutions Yes I was thinking of an auto sort as I add in new data and display the sorted results on another worksheet. I trying to learn how to do this. Thanks
@Ron-el6zh
@Ron-el6zh 2 ай бұрын
Love the ideas behind this video. I understand the code, however when I run it from Method 3 onwards I get Run-Time error '1004': Application-defined or object-defined error. The template sheet is active, I added an extra line of code to activate the worksheet. I do not know why I am getting this error? Worksheets("Template").Activate Sheets("Template").Range(Range("E2").Value).Value = _ Sheets("Template").Range(Range("H1").Value).Value
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 2 ай бұрын
Range("E2").Value looks at the active sheet because no worksheet name is mentioned If you're on the Template sheet, it will look at the cell E2 on the Template sheet - I'm not sure that's what you want it to do?
@Ron-el6zh
@Ron-el6zh 2 ай бұрын
@@TigerSpreadsheetSolutions That was the issue, both E2 and H1 were empty. Method 3 is working!! You mentioned Excel Basic Course, I need to brush up, its been about 15 years since I looked at VBA. I wish Microsoft improved its error messages, it chews up so much time trying to track errors down. Thanks so much for your reply, looking forward to going through your course.
@muslimsiroha
@muslimsiroha 2 жыл бұрын
Dear Sir we have three sheet 1. MR Form 2. SMR 3. Master Sheet First we make MR Form For the Request so we need to automatically Data Transfer with SMR Sheet and Master sheet and save data after that when we received material we can edit SMR Sheet with other details which cells is blank so when we need to update SMR Sheet then automatically we need to save with Master Sheet so please I want your help i will be provide you excel sheet
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions Жыл бұрын
You can learn the required skills on the channel - good luck!
@arljunelmacasling8497
@arljunelmacasling8497 5 күн бұрын
Hi Sir! Can I ask? where can I put these codes?
@TigerSpreadsheetSolutions
@TigerSpreadsheetSolutions 4 күн бұрын
Put them in the VBA editor - see our beginner VBA videos for more!
@arljunelmacasling8497
@arljunelmacasling8497 4 күн бұрын
@@TigerSpreadsheetSolutions Okay sir, thank you; by the way, I'm constructing a fuel consumption form with VBA, and it requires a monthly summary report with five distinct sorts of structured forms. I'm grateful for your videos since they push me to accomplish my task, even if I'm still slow I can still notice progress.
The Ultimate Guide to Copying Data using Excel VBA
31:05
Excel Macro Mastery
Рет қаралды 63 М.
Excel VBA: Copy Data Between ANY Two Sheets
12:56
Excel Macro Mastery
Рет қаралды 118 М.
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 177 МЛН
Beautiful gymnastics 😍☺️
00:15
Lexa_Merin
Рет қаралды 15 МЛН
마시멜로우로 체감되는 요즘 물가
00:20
진영민yeongmin
Рет қаралды 33 МЛН
How to Copy Data from Another Workbook in Excel Using VBA
29:09
Essential Excel
Рет қаралды 40 М.
Extract Data to Separate Sheets the Right Way!
8:34
MyOnlineTrainingHub
Рет қаралды 165 М.
Try This New Formula Instead of Pivot Tables
12:08
Kenji Explains
Рет қаралды 292 М.
Don't Use Excel Filters! Use This Incredible Excel Formula Instead ...
9:32
Tiger Spreadsheet Solutions
Рет қаралды 995 М.
VBA Macro to Copy Data from Another Workbook in Excel
13:39
Excel Campus - Jon
Рет қаралды 634 М.
Say Goodbye to IF Statements in Excel with SWITCH
7:45
Teacher's Tech
Рет қаралды 468 М.
Она была безумно рада от увиденного 🤯
0:29
Фильмы I Сериалы
Рет қаралды 1,8 МЛН
Mother Cat Drinks Lots of Coffee to Get By #funny #catlover #cuteanimals #cartoon
0:21