Combine two lists if data entered in adjacent columns


New Member
Feb 26, 2009
I am using the code below to combine two lists. (PS. found it on this site - thanks much!)

List 1 is in columns B:D and is a predetermined list of qualifying schools. Column B contains those school names. Columns C and D are used for data entry of an address and contact for each school, but not every school will have data entered for it.

List 2 is a dynamic list of non-qualifying schools in the same format; column F is the school name, column G is the address, and column H is the contact. Any school being added to the database that is not on the qualifying list gets added to this list along with data for its address and contact.

The code works in that it creates one sorted list made up of every school in the qualifying list 1 and the schools entered in the non-qualifying list 2.

I'd like to modify it so that the combined list only takes schools from list 1 if data has been entered for them in columns C and D.

There's probably and easy way to do this, but I'm stumped. Any help would be appreciated.

Dim LastRow1 As Long
Dim LastRow2 As Long
LastRow1 = Range("B" & Rows.Count).End(xlUp).Row
LastRow2 = Range("F" & Rows.Count).End(xlUp).Row
Range("B8:B" & LastRow1).Copy Range("O8")
Range("F8:F" & LastRow2).Copy Range("O" & LastRow1 + 1)
Range("O8:O" & LastRow1 + LastRow2 + 1).AdvancedFilter xlFilterCopy, , Range("P8"), True
Range("P8:P" & LastRow1 + LastRow2 + 1).Sort Key1:=Range("P8"), Order1:=xlAscending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest


Board Regular
Nov 3, 2005

Try this....

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> SortSchools()<br>    <SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> x = 8 <SPAN style="color:#00007F">To</SPAN> Range("B65536").End(xlUp).Row<br>        <SPAN style="color:#00007F">If</SPAN> Range("C" & x).Value <> "" And Range("D" & x).Value <> "" <SPAN style="color:#00007F">Then</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Range("O8").Value = "" <SPAN style="color:#00007F">Then</SPAN><br>                Range("B" & x).Copy Range("O8")<br>            <SPAN style="color:#00007F">Else</SPAN><br>                Range("B" & x).Copy Range("O" & Range("O65536").End(xlUp).Row + 1)<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        End <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> x<br>    Range("F8:F" & Range("F65536").End(xlUp).Row).Copy Range("O" & Range("O65536").End(xlUp).Row + 1)<br>    Range("O8:O" & Range("O65536").End(xlUp).Row).AdvancedFilter xlFilterCopy, , Range("P8"), <SPAN style="color:#00007F">True</SPAN><br>    Range("P8:P" & Range("P65536").<SPAN style="color:#00007F">End</SPAN>(xlUp).Row).Sort Key1:=Range("P8"), Order1:=xlAscending, Header:= _<br>        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _<br>        DataOption1:=xlSortNormal<br>    Range("O:O").Delete<br>End <SPAN style="color:#00007F">Sub</SPAN></FONT>

I left most of your code in tact, just adding a filter routine to reject cells in list 1 that do not have an address or contact.

Also used a little different method for finding the last row.

Upvote 0

Forum statistics

Latest member

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
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 "".
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