Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2023, 06:14 PM
Aussiebear Aussiebear is offline How to copy a value from source workbook if if doesn't exist in Active workbook Mac OS X How to copy a value from source workbook if if doesn't exist in Active workbook Office 2016 for Mac
Novice
How to copy a value from source workbook if if doesn't exist in Active workbook
 
Join Date: Jun 2023
Posts: 5
Aussiebear is on a distinguished road
Default How to copy a value from source workbook if if doesn't exist in Active workbook

New to this forum so if I make a mistake, please don't hang me.. I am seeking a method of copying a value from column c in source workbook to column c in Activeworkbook, if it doesn't already exist.
Reply With Quote
  #2  
Old 07-15-2023, 02:16 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: 871
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

If the cells' row numbers correspond and the blanks you want to fill are truly blank then it could be as simple as:
Code:
'copying from Sheet1 to Sheet2 where sheet2 has true blank cells:
For Each cll In Sheets("Sheet2").Range("C3:C15").SpecialCells(xlCellTypeBlanks).Cells
  Sheets("Sheet1").Range(cll.Address).Copy cll
  'or
  'cll.Value = Sheets("Sheet1").Range(cll.Address).Value
Next cll
This was between sheets in the same workbook, so you'll need to qualify the workbooks as well.
Reply With Quote
  #3  
Old 07-15-2023, 05:08 PM
Aussiebear Aussiebear is offline How to copy a value from source workbook if if doesn't exist in Active workbook Mac OS X How to copy a value from source workbook if if doesn't exist in Active workbook Office 2016 for Mac
Novice
How to copy a value from source workbook if if doesn't exist in Active workbook
 
Join Date: Jun 2023
Posts: 5
Aussiebear is on a distinguished road
Default

Thank you P45cal.
Reply With Quote
  #4  
Old 07-15-2023, 05:17 PM
Aussiebear Aussiebear is offline How to copy a value from source workbook if if doesn't exist in Active workbook Mac OS X How to copy a value from source workbook if if doesn't exist in Active workbook Office 2016 for Mac
Novice
How to copy a value from source workbook if if doesn't exist in Active workbook
 
Join Date: Jun 2023
Posts: 5
Aussiebear is on a distinguished road
Default

I'm not sure if I'm not being clear enough in my request. Source workbook Sheet 1 Column c contains a list of names and I'm looking to copy these over to the Active Workbook, Sheet 1 Column C. If the name already exists in the Target workbook then don't copy, as Active workbook Sheet 1.column C needs to be a unique list of names.

My original thinking was to simply copy the full column over and then create a Unique list afterwards, but then I thought why not simply copy the name over if it didn't already exist. Am I wrong on both accounts as the best method?
Reply With Quote
  #5  
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: 871
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
  #6  
Old 07-16-2023, 04:10 PM
Aussiebear Aussiebear is offline How to copy a value from source workbook if if doesn't exist in Active workbook Mac OS X How to copy a value from source workbook if if doesn't exist in Active workbook Office 2016 for Mac
Novice
How to copy a value from source workbook if if doesn't exist in Active workbook
 
Join Date: Jun 2023
Posts: 5
Aussiebear is on a distinguished road
Default

Okay I'll give that a go. Thank you once again P45cal.
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 07:22 AM.


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