Forum Discussion
Rory123908
Dec 02, 2021Copper Contributor
Combining rows from 2 sheets that matches using VBA/macro
Hello everybody & thankyou in advance for considering my problem! I have 2 sheets. Sheet 1 (26 columns by 85896 rows) and Sheet 2 (15 columns by 43201 rows).
Both of the sheets contain different variables with different values however they both share similarities in the time column (column A). For example, Sheet 1 records data almost every 1 second of a day while Sheet 2 records data every 2 seconds of the day. I am looking to create a macro so that I am able to compare the time column in sheet 1 to sheet 2, if it matches, I would like to copy the row of data from both sheets and put it into a new sheet 3. The result would be a fresh sheet (sheet 3), that contains the data from both tools/sheets when they are recorded at the same time.
Currently I am really struggling with this, any help would be really really appreciated! Thanks so much for having a look at this, and if you can help, please let me know! Thanks again!
- Riny_van_EekelenPlatinum Contributor
Rory123908 I'd suggest you forget about VBA and look into PowerQuery in stead. Quite easy, I dare to say, though difficult to demonstrate with some real data to play with. Can you upload a file that represents the actual structure of your real sheets/tables? Say, a hundred rows of data in each or so, with matching time-stamps between the two. Remove any private and/or confidential information, though.
- Rory123908Copper ContributorHi there, many thanks for your response! I have uploaded a file representing my problem, 100 rows long. As you may see, each sheet represents the responses from a tool that records data. They were both recorded/taken at the same time, but at different frequencies and with the occasional missing data point. I am looking to combine the responses into a new sheet (sheet 3), so that each row on sheet 3 represents a point where all variables share recordings at the same time.
- Riny_van_EekelenPlatinum Contributor
Rory123908 Thanks! Attached file now includes a sheet with records from both tables, every 2nd second. Is that what you had in mind. The PQ steps are relatively simple but it needs getting used to if you have never worked with it before.
This would be a good starting point to learn more about it.