PC Review


Reply
Thread Tools Rate Thread

Compare 2 col listings n append items in A not in B to bottom of B

 
 
Max
Guest
Posts: n/a
 
      26th Dec 2009
In Sheet1 (the codename)
In B19 down is a list of unique items:
xx
yy
zz

In Sheet2 (the codename)
In A3 down is another list of unique items:
aa
yy
bb

I need a sub to compare the 1st list with the 2nd, and to append any items
in the 1st which are not found in the 2nd list, to the bottom of the 2nd
list. Example, for the sample data above, the 2nd list should finally look
like this:
aa
yy
bb
xx
zz

(xx, zz are appended)

The sub is to reference the 2 codenames
Thanks for insights

 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      26th Dec 2009
Hi Max,

Try the following.

Sub AppendMissingData()

Dim rng1 As Range
Dim rng2 As Range
Dim cel As Range
Dim foundCel As Range

With Sheet1
Set rng1 = .Range("B19", _
.Cells(.Rows.Count, "B").End(xlUp))
End With

With Sheet2
Set rng2 = .Range("A3", _
.Cells(.Rows.Count, "A").End(xlUp))
End With

For Each cel In rng1
Set foundCel = rng2 _
.Find(What:=cel.Value, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)

If foundCel Is Nothing Then

Sheet2.Cells(Sheet2.Rows.Count, "A") _
.End(xlUp).Offset(1, 0) = cel.Value

End If

Next cel
End Sub

--
Regards,

OssieMac


 
Reply With Quote
 
Max
Guest
Posts: n/a
 
      26th Dec 2009
That was marvellous, OssieMac !
Many thanks for your sub

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      26th Dec 2009
Thanks for the feed back Max. However, I have realized that if the range in
sheet1 had multiple instances of 'new' values that are the same, it will
append them multiple times in sheet2. If there will never be multiple
instances of the 'new' data then no problem but if there can be then replace
the sheet2 range code with the following and it will always test against the
updated list including any appended data and only append one instance of
missing data.

With Sheet2
Set rng2 = .Range("A3", _
.Cells(.Rows.Count, "A"))
End With

--
Regards,

OssieMac


"Max" wrote:

> That was marvellous, OssieMac !
> Many thanks for your sub
>

 
Reply With Quote
 
Max
Guest
Posts: n/a
 
      26th Dec 2009
Noted with thanks, OssieMac.
It should not happen (dups in Sheet1) but you never know


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any way to append some items to List box, without retrieving all items through AJAX? Anjan Bhowmik Microsoft ASP .NET 1 14th Feb 2008 09:02 PM
Compare and append Johny Microsoft Access VBA Modules 1 29th Mar 2007 01:59 AM
compare and append tables =?Utf-8?B?bHlubiBhdGtpbnNvbg==?= Microsoft Access Queries 2 13th Oct 2005 06:00 PM
Compare and Append BFord Microsoft Excel Programming 2 3rd Jan 2004 05:15 AM
How to append signature as disclaimer at bottom of Email SPXtech Microsoft Outlook 0 23rd Oct 2003 08:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:00 AM.