Keep addresses with apartment numbers using a wildcard

Myke50701

New Member
Joined
May 9, 2022
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
  2. Web
Wish I would have learned about macros years ago! It's time to bring in the experts since can't figure it out or find a post that answers my issue.
I'm keeping rows with certain addresses and deleting all other rows. I'm trying to avoid having to type in each individual address and unit number in large buildings by using a wildcard for the unit number or letter.
i.e. 225-* E 6TH ST would find any unit number at 225 E 6TH ST that is listed in the report.
I found the formula below in a post but I can't get a wild card to work after the hyphen in the addresses with unit numbers. I've tried both * and ??? wildcards.
I trimmed the posted formula below down to a few addresses. Each week I run the formula there will be a large quantity of new addresses without and addresses with unit numbers to search through.

VBA Code:
Sheets("Addresses01").Select
    Range("A1").Select
    Const lngStartRow As Long = 2 'Starting data row number. Change to suit.
    
    Dim lngMyCol As Long, _
        lngMyRow As Long
    Dim xlnCalcMethod As XlCalculation
            
    With Application
        xlnCalcMethod = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With

    lngMyCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
    lngMyRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    With Columns(lngMyCol)
        With Range(Cells(lngStartRow, lngMyCol), Cells(lngMyRow, lngMyCol))
                        .Formula = "=VLOOKUP(D2,{""715-A MULBERRY ST"";""715-F MULBERRY ST"";""225-100 E 6TH S"";""225-299 E 6TH ST""; ""3421-1 W 9TH ST"";; ""3421-30 W 9TH ST""},1,FALSE)"
             ActiveSheet.Calculate
            .Value = .Value
        End With
        On Error Resume Next 'Turn error reporting off - OK to ignore 'No cells found' message
            .SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
        On Error GoTo 0 'Turn error reporting back on
        .Delete
    End With
        With Application
        .Calculation = xlnCalcMethod
        .ScreenUpdating = True
End With
    Cells.Select
    Selection.Columns.AutoFit
    Range("A1").Select
    ActiveWorkbook.Save
' Stops automated process and waits for a key press if included - MsgBox "All rows where the status was not one of the desired statuses have now been deleted.", vbInformation
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,215,787
Messages
6,126,905
Members
449,348
Latest member
Rdeane

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