I am trying without success to write a vba procedure to delete a duplicate range of cells. The object of the procedure is to define one range of cells and if the code finds a match it should delete the range that matches. This worksheet was imported data from a text file.
The error is happening on the If Sheets("RawImport").Range(rng1).Value = rngFind Then line. Currently the code says the rngFind is Nothing but I know that a match exists on lines 460 - 478 on the RawImport Sheet. Any help is appreciated.
The error is happening on the If Sheets("RawImport").Range(rng1).Value = rngFind Then line. Currently the code says the rngFind is Nothing but I know that a match exists on lines 460 - 478 on the RawImport Sheet. Any help is appreciated.
Code:
Dim lngLastRow As Long
Dim lngLoop1 As Long
Dim lngLoop2 As Long
Dim wrkbk As Excel.Workbook
Dim wrkShSrc As Excel.Worksheet
Dim wrkShDest As Excel.Worksheet
Dim lngRangeStart() As Variant
Dim lngRangeEnd() As Variant
Dim rng1 As Range
Dim rng2 As Range
Dim rng() As Variant
Dim rngFind As Range
Dim strRange As String
Dim strEnd1 As String
'On Error Resume Next
Set wrkbk = ActiveWorkbook
Set wrkShSrc = wrkbk.Worksheets("RawImport")
Set wrkShDest = wrkbk.Worksheets("Results")
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set rng1 = Range("A190:A208")strRange = "A209:A" & lngLastRow
Set rngFind = wrkShSrc.Range("A209:A" & lngLastRow).Find(What:=strRange, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Sheets("RawImport").Range(rng1).Value = rngFind Then
Sheets("RawImport").Range(rngFind).RemoveDuplicates Columns:=Array(1, 1), Header:=xlNo
'Deletes all rows after A209
Sheets("RawImport").Range(rngFind).EntireRow.Delete
End If