View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JW[_2_] JW[_2_] is offline
external usenet poster
 
Posts: 638
Default Look for new entries in data

Here's one way. This could be done without all of the variables, but
it just makes modifications a little easier. Keep in mind, this does
not remove anything from sheet3 before placing in the new data. It
simply identifies the first available cells in column A and places the
data there. It also ony does column A, not the entire row. That is a
simple change if that is what you want though.

Sub newEntry()
Dim searchRange As Range, r As Range
Dim searchSht As Worksheet
Dim valSheet As Worksheet
Dim placementSheet As Worksheet
Dim valRange As Range
Set searchSht = Sheets("Sheet1")
Set valSheet = Sheets("Sheet2")
Set placementSheet = Sheets("Sheet3")
Set valRange = valSheet.Range _
(valSheet.Cells(2, 1), _
valSheet.Cells(valSheet.Rows.Count, 1) _
.End(xlUp))
Set searchRange = searchSht.Range _
(searchSht.Cells(2, 1), _
searchSht.Cells(searchSht.Rows.Count, 1) _
.End(xlUp))
For Each r In valRange
If WorksheetFunction.CountIf(searchRange, _
r.Text) = 0 Then
placementSheet.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Value = r.Text
End If
Next r
Set searchSht = Nothing
Set valSheet = Nothing
Set placementSheet = Nothing
Set valRange = Nothing
Set searchRange = Nothing
End Sub
Steve wrote:
Hi everyone. Given a block of data in Sheet1 column A. Can I have
vba cross reference that data against data in Sheet2 column A and make
a list (on sheet3) of ALL entries that exist on Sheet2 but NOT on
Sheet1? Thanks!