VBA to check if value in column exists and if not paste

Drivingman

New Member
Joined
Jan 26, 2012
Messages
19
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
HI All

Been looking all morning for this, and found a few things that I thought should work but not getting the outcome I want or how to amend it to suit perfectly.
We have a call log sheet that is received daily working on complaints. These are then amended to include any additional comments, or their status may change, the only constant is their identifier in column A:A.

The upload goes into sheet named "Upload", and I want it to check for any instance of the Identifier (from A3 downwards) in the identifier for any instance of it already happening in the sheet "Complaints 03.09.18". If the value is found then it will move down and look for the next value.
If the value is not found, then it will copy and paste from "Upload" all data from columns A:Q in that row, in the next clear row within Complaints sheet, and so on.

Once the sheet gets down to the final value - or first clear row to stop.
All data is within the same excel sheet now.
Hope this makes sense.
TYIA. :)
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Are the col A identifiers unique?
 
Upvote 0
Assuming that the answer to my question is yes, try
Code:
Sub CheckUpload()
   Dim cl As Range
   Dim Uws As Worksheet, Cws As Worksheet
   
   Set Uws = Sheets("Upload")
   Set Cws = Sheets("Complaints")
   
   With CreateObject("scripting.dictionary")
      For Each cl In Uws.Range("A2", Uws.Range("A" & Rows.count).End(xlUp))
         .Item(cl.Value) = Empty
      Next cl
      For Each cl In Cws.Range("A2", Cws.Range("A" & Rows.count).End(xlUp))
         If .exists(cl.Value) Then .Remove cl.Value
      Next cl
      If Uws.AutoFilterMode Then Uws.AutoFilterMode = False
      Uws.Range("A1:Q1").AutoFilter 1, .keys, xlFilterValues
      Uws.AutoFilter.Range.Offset(1).Copy Cws.Range("A" & Rows.count).End(xlUp).Offset(1)
      Uws.AutoFilterMode = False
   End With
End Sub
 
Upvote 0
HI

Thanks for this but when I copy this in and run it I get the following error:

Run-time error '13'

Type mismatch

When I debug it highlights:
Uws.Range("A1:Q1").AutoFilter 1, .keys, xlFilterValues
 
Upvote 0
Are you sure that there are values in the upload sheet that are not present in the complaints sheet?
 
Upvote 0
You are a genius. I should have checked that first and not assumed that there were new individual values today. Normally are - by the bucket load!!!!!
 
Upvote 0
Add the line in blue & if there is nothing to add it will bypass the final portion of code.
Code:
Sub CheckUpload()
   Dim cl As Range
   Dim Uws As Worksheet, Cws As Worksheet
   
   Set Uws = Sheets("pcode")
   Set Cws = Sheets("Complaints")
   
   With CreateObject("scripting.dictionary")
      For Each cl In Uws.Range("A2", Uws.Range("A" & Rows.count).End(xlUp))
         .Item(cl.Value) = Empty
      Next cl
      For Each cl In Cws.Range("A2", Cws.Range("A" & Rows.count).End(xlUp))
         If .exists(cl.Value) Then .Remove cl.Value
      Next cl
      If Uws.AutoFilterMode Then Uws.AutoFilterMode = False[COLOR=#0000ff]
      If .count = 0 Then MsgBox "Nothing to add": Exit Sub[/COLOR]
      Uws.Range("A1:Q1").AutoFilter 1, .keys, xlFilterValues
      Uws.AutoFilter.Range.Offset(1).Copy Cws.Range("A" & Rows.count).End(xlUp).Offset(1)
      Uws.AutoFilterMode = False
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top