Solved

Fill in missing rows using Date column

Posted on 2016-09-02
5
44 Views
Last Modified: 2016-09-04
I am trying to fill in missing data based on a Date column from one sheet to another.

In Sourcebook1.xlsx, there are rows of data with a date in column E
In DestBook1.xlsx, there are rows of data with a date also in column E.
What I want is to copy the group of rows from sourcebook1 to Destbook1 for any dates that do not exist in Destbook1.

For example, in DestBook1, there are no rows with a date of 7/30/16. In Sourcebook1, there are 762 rows with a date of 7/30 so I want to copy those 762 rows to DestBook1 after the last current row, then resort the sheet so the data is sorted by date.

DestBook1 also has no rows with a date of 4/9/2016 so again, copy the rows from SourceBook1 to DestBook1.

Lastly I need a message box that says either:
"No rows were copied" (meaning there were no missing dates in DestBook1)
Or "Missing Dates 4/9/16, 7/30/16 were copied".

Hope I explained this clearly and thanks for your help in advance.

swjtx99
DestBook1.xlsx
SourceBook1.xlsx
0
Comment
Question by:swjtx99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 31

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41782926
Please find the attached with the code and with a button called "Copy Data From Source Workbook".
Please click the button to run the code. The code will prompt you to select the source workbook and copy data from the source workbook for the dates which are missing in the macro workbook.
DestBook1.xlsm
0
 

Author Closing Comment

by:swjtx99
ID: 41783299
Hi Subodh,

This is great!

Can you advise how I can copy more columns? The example only had 5 columns but the production version has 15 (up to column O)

Thank you very much for your help!

swjtx99
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41783379
You're welcome.

In that case you only need to replace the following lines of code...
This Line
sws.Range("A2:E" & slr).SpecialCells(xlCellTypeVisible).Copy ws.Range("A" & Rows.Count).End(3)(2)

Open in new window

With This
sws.Range("A2:O" & slr).SpecialCells(xlCellTypeVisible).Copy ws.Range("A" & Rows.Count).End(3)(2)

Open in new window


AND

This Line
ws.Range("A2:E" & lr).Sort key1:=ws.Range("E2"), order1:=xlAscending, Header:=xlGuess

Open in new window

With This
ws.Range("A2:O" & lr).Sort key1:=ws.Range("E2"), order1:=xlAscending, Header:=xlGuess

Open in new window

0
 

Author Comment

by:swjtx99
ID: 41784107
That worked. Thanks again,
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41784209
You're welcome.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question