VBA - How to check against array?

gentleGiant

New Member
Joined
Sep 9, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am new to VBA and need some help. I am trying to delete all the rows of data that I do not want based on the names of people that I do want the call logs for. I think I almost have it figured out but I don't know how to check against an array. The actual spreadsheet I am working with has about 15k rows with over 150 names and I only want data for 40 of the names and delete the rest.

Any help is greatly appreciated!

Sub PhoneLogs()

Dim StatusCol As Range
Dim Status As Range
Dim LR As Long

'These are all the folks on the Team I want to get call logs for
MyArray = Array("Daisy", "Donald Duck")

'This gets the last row number
LR = Cells(Rows.Count, 1).End(xlUp).Row

'This sets the area for "StatusCol" variable from A2 to Last row that has data
Set StatusCol = Range("A2:A" & LR)


For Each Status In StatusCol

'This is what I need help with, I don't know how to check against an array
If "Status is not in Array" Then
Status.EntireRow.ClearContents

End If

Next Status

End Sub
 

Attachments

  • CallLogs.png
    CallLogs.png
    9.5 KB · Views: 11

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try:
VBA Code:
Sub PhoneLogs()
    Application.ScreenUpdating = False
    Dim MyArray As Variant, v As Variant, x As Variant, i As Long, delRng As Range
    Set delRng = Cells(Rows.Count, 1).End(3).Offset(1, 0)
    MyArray = Array("Daisy", "Donald Duck")
    v = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
    For i = LBound(v) To UBound(v)
        x = Application.Match(v(i, 1), MyArray, 0)
        If IsError(x) Then
            Set delRng = Union(delRng, Range("A" & i + 1))
        End If
    Next i
    delRng.EntireRow.Delete
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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