Please consider the code below:
Code:
Private Function listNumbers(fileName As String, sheetName As String, columnName As String) As Long()
Dim result() As Long
Dim resultLength As Integer
Dim rangeName As String
Dim wb As Workbook
Dim rangeStartRow As Integer
Dim sh As Worksheet
Dim needToClose As Boolean
Dim i As Integer
needToClose = True
For i = 1 To Workbooks.Count
If Workbooks(i).FullName = fileName Then
needToClose = False
Set wb = Workbooks(i)
End If
Next
rangeStartRow = 1 ' change this as required
If needToClose Then
Set wb = Workbooks.Open(fileName, ReadOnly:=True)
End If
Set sh = wb.Worksheets(sheetName)
resultLength = sh.Cells(sh.Rows.Count, columnName).End(xlUp).Row - rangeStartRow + 1
ReDim result(resultLength - 1)
For i = 1 To resultLength
result(i - 1) = sh.Range(columnName & (rangeStartRow + i - 1)).Value
Next
listNumbers = result
If needToClose Then
wb.Close SaveChanges:=False
End If
End Function
Public Sub DeleteRows()
Dim numbers() As Long
Dim pos As Variant
Dim cellNumber As Long
Dim cl As Range
numbers = listNumbers("D:\aa\Book1.xlsx", "Sheet1", "A")
For Each cl In ActiveSheet.Range("A:A").Cells
If Not IsNumeric(cl.Value) Then
Exit For
End If
cellNumber = cl.Value
pos = Application.Match(cellNumber, numbers, False)
If Not IsError(pos) Then
' mark the row for deletion
End If
Next
End Sub
I have not added any error handling or ScreenUpdating switching - and have not coded the actual deletion.
Let me know if you have any questions.