Code VBA to filter array by text

Excelpromax123

Board Regular
Joined
Sep 2, 2021
Messages
167
Office Version
  1. 2010
Platform
  1. Windows
I need to filter by array by 2 criteria "A" and "A-*". I have used the code below but it doesn't work. I need to support a spreadsheet I have about 200,000 lines so I can't do it with formulas

VBA Code:
Sub text()
On Error Resume Next
Dim sArr(), dArr(), Dk1 As String, I As Long, K As Long, R As Long, Col As Long
sArr = Range("B5:C15").Value 'input
R = UBound(sArr)
ReDim dArr(1 To R, 1 To 2)
For I = 1 To R
    If UCase(sArr(I, 1)) = "A" Or UCase(sArr(I, 1)) = "A-*" Then
        K = K + 1
        For Col = 1 To 2
            dArr(K, Col) = sArr(I, Col)
        Next Col
    End If
Next I
' OUTPUT
Range("F5:G15").ClearContents
Range("I5").Resize(K, 2) = dArr '
End Sub

1633704084213.png
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
How about
VBA Code:
If UCase(sArr(I, 1)) = "A" Or UCase(sArr(I, 1)) Like "A-*" Then
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,253
Messages
6,123,891
Members
449,131
Latest member
leobueno

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