I'm kind of confused.
Do you mean you want to delete the row if it doesn't match any name in that
array? (Or keep it if the name matches one of the names in the array)
Option Explicit
Sub testme()
Dim myArray As Variant
Dim Firstrow As Long
Dim Lastrow As Long
Dim lRow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim KeepIt As Boolean
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
myArray = Array("TotalTasks", "adkinj10", "henderk6", _
"brownm33", "burnsd13", "deverea", _
"devitof", "englank", "evansd15", _
"hagertm", "heltonm", "jonesb36", _
"matthie1", "murphj22", "petrica", _
"philharb", "shawd2", "shermab5", _
"sullivd", "thomac30", "walkdt")
With ActiveSheet
.DisplayPageBreaks = False
Firstrow = 1
'still using column K to get the lastrow
Lastrow = .Cells(.Rows.Count, "K").End(xlUp).Row
For lRow = Lastrow To Firstrow Step -1
KeepIt = False
If IsNumeric(Application.Match(.Cells(lRow, "K"), myArray, 0)) _
Or IsNumeric(Application.Match(.Cells(lRow, "B"), myArray, 0)) _
Then
KeepIt = True
'stop looking for more matches
Exit For
End If
If KeepIt = True Then
'do nothing, it's on the list (somewhere)
Else
'it's not the list, so delete it
.Rows(lRow).Delete
End If
Next lRow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
(Compiled, but untested.)
Marcusdmc wrote:
>
> I was trying to rearrange the outcome of the if then else statement to
> turn this around and actually delete the rows in the array as opposed
> to deleting them, but I am coming up with nothing happening when I try
> this, am I going about it the wrong way?
>
> Dim myArray As Variant
> Dim Firstrow As Long
> Dim Lrow As Long
> Dim CalcMode As Long
> Dim ViewMode As Long
>
> With Application
> CalcMode = .Calculation
> .Calculation = xlCalculationManual
> .ScreenUpdating = False
> End With
>
> ViewMode = ActiveWindow.View
> ActiveWindow.View = xlNormalView
>
> myArray = Array("TotalTasks", "adkinj10", "henderk6", "brownm33",
> "burnsd13", "deverea", "devitof", "englank", "evansd15", "hagertm",
> "heltonm", "jonesb36", "matthie1", "murphj22", "petrica", "philharb",
> "shawd2", "shermab5", "sullivd", "thomac30", "walkdt")
>
> With ActiveSheet
> .DisplayPageBreaks = False
> Firstrow = 1
> 'still using column K to get the lastrow
> LastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
> For Lrow = LastRow To Firstrow Step -1
> If IsNumeric(Application.Match(.Cells(Lrow, "K"), myArray,
> 0)) _
> Or IsNumeric(Application.Match(.Cells(Lrow, "B"),
> myArray, 0)) _
> Then
> 'it's on the list, so delete it
> .Rows(Lrow).Delete
> Else
> 'not on the list, so keep the row
> End If
> Next Lrow
> End With
>
> ActiveWindow.View = ViewMode
> With Application
> .ScreenUpdating = True
> .Calculation = CalcMode
> End With
>
> -Marcus
--
Dave Peterson