Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 74
Default Comparing List A to List B and add what's missing from List B

Hi,

I have workbook with two worksheets. Sheet1 pulls projects with activity
and Sheet1 pulls all the projects with and without activity. What I need is
a formula or macro that compares sheet1 to sheet2 and returns the projects
from sheet2 that do not exist in sheet1. I would like to see those right
underneath the list in sheet1. I'm using excel 2007 and the projects format
is text. Thank you in advance.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Comparing List A to List B and add what's missing from List B

This macro should do it for you. Change the values of the 4 'Const' declared
values to match the sheet names and column identifiers actually used in your
workbook.

To put the code into your workbook, press [Alt]+[F11] to open the VB Editor,
choose Insert -- Module from its menu. Copy the code below and paste it
into the module presented to you. Make changes to the code as needed. Make
sure you have macros enabled, and run the macro from the Developer tab or as
you may setup already to get to macros easily.

LIMITATION: obviously once it has been run once, all projects from both
sheets are going to be listed on the first sheet. I 'marked' the boundary so
that if you need to refresh the list later, you can delete entries from the
'boundary' entry on down the sheet, run it again, and get an up-to-date list.

Sub ListMissingProjects()
'name of sheet1 with projects & activities
Const s1Name = "Sheet1" ' change as required
'column projects are listed in on sheet1
Const s1PCol = "A" ' change as required
'name of sheet with projects only on it
Const s2Name = "Sheet2" ' change as required
'column on 2nd sheet with projects list
Const s2PCol = "A" ' change as required
Dim s1WS As Worksheet
Dim s1List As Range
Dim anyS1Entry As Range
Dim s2WS As Worksheet
Dim s2List As Range
Dim anyS2Entry As Range
Dim foundFlag As Boolean

'get the address of projects listed on sheet1
Set s1WS = Worksheets(s1Name)
Set s1List = s1WS.Range(s1PCol & "1:" & _
s1WS.Range(s1PCol & Rows.Count).End(xlUp).Address)
'get the address of projects listed on sheet2
Set s2WS = Worksheets(s2Name)
Set s2List = s2WS.Range(s2PCol & "1:" & _
s1WS.Range(s2PCol & Rows.Count).End(xlUp).Address)
'mark the 'boundary'
s1WS.Range(s1PCol & Rows.Count).End(xlUp). _
Offset(1, 0) = "Unlisted Projects from " & s2Name
For Each anyS2Entry In s2List
foundFlag = False
For Each anyS1Entry In s1List
If anyS1Entry = anyS2Entry Then
'it is already in the list
foundFlag = True
Exit For ' out of inner loop
End If
Next
If foundFlag = False Then
'must add to list on sheet1
s1WS.Range(s1PCol & Rows.Count).End(xlUp). _
Offset(1, 0) = anyS2Entry
End If
Next
'good housekeeping
Set s1List = Nothing
Set s2List = Nothing
Set s1WS = Nothing
Set s2WS = Nothing
End Sub


"Gilbert" wrote:

Hi,

I have workbook with two worksheets. Sheet1 pulls projects with activity
and Sheet1 pulls all the projects with and without activity. What I need is
a formula or macro that compares sheet1 to sheet2 and returns the projects
from sheet2 that do not exist in sheet1. I would like to see those right
underneath the list in sheet1. I'm using excel 2007 and the projects format
is text. Thank you in advance.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 74
Default Comparing List A to List B and add what's missing from List B

Worked great JLatham. I appreciate your help.

"JLatham" wrote:

This macro should do it for you. Change the values of the 4 'Const' declared
values to match the sheet names and column identifiers actually used in your
workbook.

To put the code into your workbook, press [Alt]+[F11] to open the VB Editor,
choose Insert -- Module from its menu. Copy the code below and paste it
into the module presented to you. Make changes to the code as needed. Make
sure you have macros enabled, and run the macro from the Developer tab or as
you may setup already to get to macros easily.

LIMITATION: obviously once it has been run once, all projects from both
sheets are going to be listed on the first sheet. I 'marked' the boundary so
that if you need to refresh the list later, you can delete entries from the
'boundary' entry on down the sheet, run it again, and get an up-to-date list.

Sub ListMissingProjects()
'name of sheet1 with projects & activities
Const s1Name = "Sheet1" ' change as required
'column projects are listed in on sheet1
Const s1PCol = "A" ' change as required
'name of sheet with projects only on it
Const s2Name = "Sheet2" ' change as required
'column on 2nd sheet with projects list
Const s2PCol = "A" ' change as required
Dim s1WS As Worksheet
Dim s1List As Range
Dim anyS1Entry As Range
Dim s2WS As Worksheet
Dim s2List As Range
Dim anyS2Entry As Range
Dim foundFlag As Boolean

'get the address of projects listed on sheet1
Set s1WS = Worksheets(s1Name)
Set s1List = s1WS.Range(s1PCol & "1:" & _
s1WS.Range(s1PCol & Rows.Count).End(xlUp).Address)
'get the address of projects listed on sheet2
Set s2WS = Worksheets(s2Name)
Set s2List = s2WS.Range(s2PCol & "1:" & _
s1WS.Range(s2PCol & Rows.Count).End(xlUp).Address)
'mark the 'boundary'
s1WS.Range(s1PCol & Rows.Count).End(xlUp). _
Offset(1, 0) = "Unlisted Projects from " & s2Name
For Each anyS2Entry In s2List
foundFlag = False
For Each anyS1Entry In s1List
If anyS1Entry = anyS2Entry Then
'it is already in the list
foundFlag = True
Exit For ' out of inner loop
End If
Next
If foundFlag = False Then
'must add to list on sheet1
s1WS.Range(s1PCol & Rows.Count).End(xlUp). _
Offset(1, 0) = anyS2Entry
End If
Next
'good housekeeping
Set s1List = Nothing
Set s2List = Nothing
Set s1WS = Nothing
Set s2WS = Nothing
End Sub


"Gilbert" wrote:

Hi,

I have workbook with two worksheets. Sheet1 pulls projects with activity
and Sheet1 pulls all the projects with and without activity. What I need is
a formula or macro that compares sheet1 to sheet2 and returns the projects
from sheet2 that do not exist in sheet1. I would like to see those right
underneath the list in sheet1. I'm using excel 2007 and the projects format
is text. Thank you in advance.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing List A to List B and add what's missing from List B Gilbert Excel Discussion (Misc queries) 1 July 20th 09 08:41 PM
validation list--list depends on the selection of first list Michael New Users to Excel 2 April 27th 06 10:23 PM
Comparing 2 list IFIXPCS Excel Discussion (Misc queries) 4 February 21st 06 10:43 PM
list 1 has 400 names List 2 has 4000. find manes from list 1 on 2 Ed Excel Worksheet Functions 5 September 12th 05 09:48 AM
find names on list 1 in list 2. list 1 4000 names list 2 400 name Ed Excel Worksheet Functions 1 September 4th 05 12:48 AM


All times are GMT +1. The time now is 07:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"