Solved

Fill in missing rows using Date column

Posted on 2016-09-02
5
37 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
  • 3
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
Comment Utility
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
Comment Utility
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 28

Expert Comment

by:Subodh Tiwari (Neeraj)
Comment Utility
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
Comment Utility
That worked. Thanks again,
0
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
Comment Utility
You're welcome.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now