Compare specific Column in two sheets and append data to last available row

Daveyd86

New Member
Joined
Apr 27, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello, I am fairly new to vba and i am having a hard time coding something that will solve my issue :(

I have two data sources I wish to combine.

Sheet 1

Data source on Sheet1 contains 2 columns: AccountID and Cost. Source is in cells A3:B3 (data row starts in A4) for 1 to N records. A secondary cell contains the year value for all records to be used in this source. It is in cell D1.

Sheet 2

Data source on Sheet2 contains 6 columns and in range A1:F1 (data starts on row 2): Year, AccountID, Location, Phone#, Email type, & Cost. Data continues for 1 to N records.

I wish to join the records of both tables based on the AccountID of each range of data (Sheet1 column A, Sheet2 column B), where the year (sourced on Sheet1!D1) is added to all records on the Sheet2 data, and records matching by AccountID. The data is appended /added to Sheet2 on last available row.

Example #1

AccountID "1234" is on Sheet1 but not on Sheet2. Year value (Sheet1!D1) contains 2020. The end result would have a new row added with the AccountID of "1234" into Sheet2, the associated Cost value, and a year of 2020.

Example #2

AccountID "1234" is on sheet1 and also on Sheet2. The record on Sheet2 has a year value of 2019. The record on Sheet1 has the year 2020 associated with it (Sheet1!D1 cell value). The end result would have two rows of data for AccountID of "1234" in Sheet2, one for the 2019 record and one for 2020 record, as found on Sheet1 data source. The latter would not include Location, Phone#, or Email type values, as they aren't specified.
 

Attachments

  • Sheet1.JPG
    Sheet1.JPG
    38.4 KB · Views: 12
  • Sheet2 once Sheet1 data is appended.JPG
    Sheet2 once Sheet1 data is appended.JPG
    110.2 KB · Views: 13
  • Sheet2.JPG
    Sheet2.JPG
    78.5 KB · Views: 13

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,214,654
Messages
6,120,758
Members
448,991
Latest member
Hanakoro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top