View Single Post
 
Old 07-16-2023, 01:27 PM
p45cal's Avatar
p45cal p45cal is offline Windows 10 Office 2021
Expert
 
Join Date: Apr 2014
Posts: 948
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

Quote:
Originally Posted by Aussiebear View Post
I'm not sure if I'm not being clear enough in my request
Probably not
Quote:
Originally Posted by Aussiebear View Post
Am I wrong on both accounts as the best method?
That may depend on how big the two ranges are and the arrangement of your data.

What version of Excel are you using?
If MS365 then you can put a temporary formula at the bottom of the existing list of the active sheet, then convert the results of that formula to plain values:
Code:
Sub blah()
Set SourceSht = Workbooks("Book2").Sheets("Sheet1") 'adjust this so that SourceSht is your source sheet.
With SourceSht
  Set RngSource = Range(.Range("C2"), .Cells(.Rows.Count, "C").End(xlUp)) 'this is your source data range; adjust C2 to the top cell of that range.
  'SourceAddress = RngSource.Address(external:=True) 'for the .formula2 version below.
  SourceAddressR1C1 = RngSource.Address(, , xlR1C1, external:=True) 'for the .Formula2R1C1 version below.
End With
With ActiveSheet
  Set DestnCell = .Cells(.Rows.Count, "C").End(xlUp).Offset(1) 'this is the single cell where the formula will go.
  Set RngExisting = .Range(.Range("C3"), DestnCell.Offset(-1)) 'this is your existing data on the active sheet, adjust C3 to the top cell of your data.
  'ExistingAddress = RngExisting.Address 'for the .formula2 version below.
  ExistingAddressR1C1 = RngExisting.Address(, , xlR1C1) 'for the .Formula2R1C1 version below.
End With
  
'choose one of these lines below:
'*********************************
DestnCell.Formula2R1C1 = "=LET(a," & SourceAddressR1C1 & ",FILTER(a,(ISERROR(MATCH(a," & ExistingAddressR1C1 & ",0)))*(a<>"""")))"
'DestnCell.Formula2 = "=LET(a," & SourceAddress & ",FILTER(a,(ISERROR(MATCH(a," & ExistingAddress & ",0)))*(a<>"""")))"
'*********************************
'Convert results to plain values:
If DestnCell.SpillingToRange Is Nothing Then
  If IsError(DestnCell) Then DestnCell.ClearContents Else DestnCell.Value = DestnCell.Value
Else
  DestnCell.SpillingToRange.Value = DestnCell.SpillingToRange.Value
End If
End Sub
A bit verbose and can be shortened/streamlined.

Older versions of Excel:
Code:
Sub blah2()
Set SourceSht = Workbooks("Book2").Sheets("Sheet1") 'adjust this so that SourceSht is your source sheet.
With SourceSht
  RngSource = Range(.Range("C2"), .Cells(.Rows.Count, "C").End(xlUp)).Value 'this is your source data; adjust C2 to the top cell of that range.
End With
With ActiveSheet
  Set DestnCell = .Cells(.Rows.Count, "C").End(xlUp).Offset(1) 'this is the single cell where the results will begin.
  RngExisting = .Range(.Range("C3"), DestnCell.Offset(-1)).Value 'this is your existing data on the active sheet, adjust C3 to the top cell of your data.
End With
For Each v In RngSource
  If Not IsEmpty(v) Then
    If Len(Application.Trim(v)) > 0 Then
      xx = Application.Match(v, RngExisting, 0)
      If IsError(xx) Then
        DestnCell.Value = v
        Set DestnCell = DestnCell.Offset(1)
      End If
    End If
  End If
Next v
End Sub
I haven't tested for case sensitivity, in fact I haven't tested extensively at all, but they can be tweaked.
Reply With Quote