Copy If Not Exists

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Good Afternoon all

Looking to copy values [to another worksheet] from Column H which are not in Column T

This Script highlights column H values not in Column T - hoping for some insight how to attain the above request.

Thanks guys.

Code:
Sub CompareRangesII()    
    Dim r As Range
    Dim Dict As Object
    Dim Sht1 As Worksheet
    
    Set Dict = CreateObject("scripting.dictionary")
    Set Sht1 = Worksheets("Test")
    
    With Dict
    .CompareMode = vbTextCompare
    For Each r In Sht1.Range("T2", Sht1.Range("T" & Rows.Count).End(xlUp))
    If Not .exists(r.Value) Then .Add r.Value, r.Row
    Next r
    'Look through list in Column H and asertain if exists in Column T
    
    For Each r In Sht1.Range("H1", Sht1.Range("H" & Rows.Count).End(xlUp))
    If Not .exists(r.Value) Then
    r.Interior.Color = RGB(184, 205, 208)
    'this highlights Column H values Not in Column T list
    r.Font.Bold = True
        End If
        Next r
        End With
    Set r = Nothing


    End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Ok, try
Code:
Sub CompareRangesII()
   Dim r As Range, Rng As Range
   Dim Dict As Object
   Dim Sht1 As Worksheet
   
   Set Dict = CreateObject("scripting.dictionary")
   Set Sht1 = Worksheets("Test")
   
   With Dict
      .CompareMode = vbTextCompare
      For Each r In Sht1.Range("T2", Sht1.Range("T" & Rows.Count).End(xlUp))
         If Not .Exists(r.Value) Then .Add r.Value, r.Row
      Next r
      'Look through list in Column H and asertain if exists in Column T
      
      For Each r In Sht1.Range("H1", Sht1.Range("H" & Rows.Count).End(xlUp))
         If Not .Exists(r.Value) Then
            If Rng Is Nothing Then Set Rng = r.Offset(, -7).Resize(, 12) Else Set Rng = Union(Rng, r.Offset(, -7).Resize(, 12))
            r.Interior.Color = RGB(184, 205, 208)
            'this highlights Column H values Not in Column T list
            r.Font.Bold = True
         End If
      Next r
   End With
   Set r = Nothing
   If Not Rng Is Nothing Then Rng.Copy Sheets("Sheet4").Range("A1")
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,833
Messages
6,181,240
Members
453,026
Latest member
cknader

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