Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2023, 01:27 PM
p45cal's Avatar
p45cal p45cal is offline How to copy a value from source workbook if if doesn't exist in Active workbook Windows 10 How to copy a value from source workbook if if doesn't exist in Active workbook Office 2021
Expert
 
Join Date: Apr 2014
Posts: 956
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Display workbook filename in title bar and use personal workbook Jamal NUMAN Excel Programming 3 08-04-2022 02:56 AM
How do I copy a workbook to another workbook and keep the formatting within the new workbook excelforsue Excel 3 09-15-2020 03:37 AM
data entered in one workbook should be updated in other relevant workbook based on the date vedha Excel 0 04-24-2015 08:45 PM
Workbook with daily active sheet MDMeyers Excel 1 01-10-2015 04:48 AM
Range(Cell1,Cell2) Error on another workbook controlling some other workbook? tinfanide Excel Programming 1 02-09-2012 04:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft