How can I modify this macro (arrays) for exclude the headers and extend the range of columns analyzed?

Lehoi

Board Regular
Joined
Jan 30, 2016
Messages
93
Hi all

I found this code in the web to compare two worksheets and delete duplicates.
I made some minor changes and it works decently, but I am stuck with this 2 things:
1- Exclude the headers
2- Analyze just not the column H, I need analyze the range from C to K, if all cells are identical in both sheets, delete duplicates (only the range C to K).

Any idea please? :pray:
Thanks
Code:
Sub CleanDupes()

Dim targetArray, searchArray
Dim targetRange As Range
Dim x As Long


'Update these 4 lines if your target and search ranges change
Dim TargetSheetName As String: TargetSheetName = "Daily Data"
Dim TargetSheetColumn As String: TargetSheetColumn = "H"
Dim SearchSheetName As String: SearchSheetName = "Matches Added"
Dim SearchSheetColumn As String: SearchSheetColumn = "H"


Application.ScreenUpdating = False
'Load target array
With Sheets(TargetSheetName)
    Set targetRange = .Range(.Range(TargetSheetColumn & "1"), .Range(TargetSheetColumn & Rows.Count).End(xlUp))
    targetArray = targetRange
End With
'Load Search Array
With Sheets(SearchSheetName)
    searchArray = .Range(.Range(SearchSheetColumn & "1"), .Range(SearchSheetColumn & Rows.Count).End(xlUp))
End With


Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
dict.CompareMode = 0
If IsArray(searchArray) Then
    For x = 1 To UBound(searchArray)
        If Not dict.exists(searchArray(x, 1)) Then
            dict.Add searchArray(x, 1), 1
        End If
    Next
Else
    If Not dict.exists(searchArray) Then
        dict.Add searchArray, 1
    End If
End If


'Delete rows with values found in dictionary
If IsArray(targetArray) Then
'Step backwards to avoid deleting the wrong rows.
    For x = UBound(targetArray) To 1 Step -1
        If dict.exists(targetArray(x, 1)) Then
            'targetRange.Cells(x).EntireRow.Delete
            targetRange.Cells(x).ClearContents
        End If
    Next
Else
    If dict.exists(targetArray) Then
        targetRange.EntireRow.ClearContents
    End If
End If
Intersect([C:K], Columns("H").SpecialCells(xlBlanks).EntireRow).Delete xlUp
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hello Lehoi,

Is it possible that the contents in a row in columns C through K on one sheet could be the same but in different order on the other sheet?
 
Upvote 0
Hi Leith Ross, thanks for replay

The data in sheet
"Matches Added" is in unique order because first I extract the data from the web and copy in sheet "Daily Data", then I copy some rows (from C to K) to sheet "Matches Added" with another macro.
The purpose of this macro is when I extract data again and paste in "Daily Data", I want to remove the data already exist in sheet "Matches Added" and only see new data.
sorry my poor english
:oops:
 
Upvote 0
Hello Lehoi,

Yo creo que se puede escribir mejor en Inglés que puedo escribir en Español.

If you could post a copy of your workbook to a public file sharing site, it would make it easier for me to provide you with a working solution.
 
Upvote 0
Hello Lehoi,

Lo siento, yo era muy tarde en la respuesta a su pregunta. Me complace que recibió una respuesta.

(Gaélico Escocés - A tu salud!)
Slàinte mhath!
 
Upvote 0
Hello Lehoi,

Lo siento, yo era muy tarde en la respuesta a su pregunta. Me complace que recibió una respuesta.

(Gaélico Escocés - A tu salud!)
Slàinte mhath!

No problem Leith, I really appreciate your interest!
No hay problema Leith, aprecio mucho su interés!
Saludos
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,573
Members
449,089
Latest member
Motoracer88

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