Hello, I am trying to write some code that will look at a column of numbers, and delete the rows that contain a number that does match any of the numbers in a specific array.
For example, say I define an array as [1,2,3,4] and my column of numbers in excel as [1,2,3,4,5,6,7,8,9]. The code will delete the rows that do not match any of the numbers in the array, in this example, rows 5, 6, 7, 8, and 9 will be deleted. Here's what I have -
Private Sub WriteToACell()
Set WS = ActiveSheet
Dim SomeArray(3) As Integer
SomeArray(0) = 1
SomeArray(1) = 2
SomeArray(2) = 3
SomeArray(3) = 4
For i = 1 To 10 Step 1
For j = 0 To 3 Step 1
If WS.Cells(i, 1).Value = SomeArray(j) Then [ Next i ]
ElseIf WS.Cells(i, 1).Value <> SomeArray(j) Then WS.EntireRow.Delete
Next j
Next i
End Sub
I'm am trying to compare each cell to the array by cycling through the array, but it doesn't seem to be working. Any help is appreciated!
Bookmarks