To find plumber listings in an Excel contact list with VBA, search the column that contains service categories or descriptions, then review the matching rows for business names and phone numbers. The macro below searches for a word or phrase such as “plumber”; it searches your workbook, not the internet, so it cannot locate a real-world plumber unless you first put listings into the sheet.
What “find a plumber” means in Excel
In this context, VBA means Visual Basic for Applications, the programming language built into desktop Excel. A VBA search can help when a worksheet contains a directory of service providers and you want to find rows whose trade, description, or notes mention plumbing. For example, a contact table might have a business name in column A, a phone number in column B, and a service category in column C.
The distinction matters: Excel’s Find feature searches cell contents. It does not check whether a business is currently operating, verify its qualifications, compare reviews, or identify providers near your location. If you are trying to hire someone, you need a current directory or search service, and you should verify the details directly with the provider. VBA is useful for searching information you already have, such as a saved vendor list or an exported directory.
Prepare the worksheet before searching
A consistent layout makes a search more dependable. Put one provider per row, use a clear header row, and keep the trade or service description in the same column for every entry. The example macro assumes row 1 contains headers, business names are in column A, phone numbers are in column B, and service descriptions are in column C. It searches column C from row 2 down.
Before running the code, check that the service descriptions contain useful terms. A row labelled “residential pipe repair” will not match a search for “plumber” unless the word appears somewhere in the cell. You could use a broader term such as “pipe,” “drain,” or “plumbing,” or improve the descriptions so they include the trade name. Consistent wording is especially helpful in imported lists, where different sources may use different labels.
Try Excel’s built-in Find first
For a one-time lookup, VBA may be unnecessary. In Excel for Microsoft 365 on Windows, press Ctrl+F, enter plumber, and use Find Next to move between matches. Choose Options if you need to control whether Excel searches within the current sheet or the whole workbook, searches values or formulas, or matches the whole cell rather than part of its contents. Find All displays a list of matches that you can inspect.
On a Mac, press Command+F to open Find. The dialog’s available controls can differ slightly from Windows, but the basic search works in the same way. If Excel finds a match in a description cell, check the rest of that row for the provider’s name and contact information. Built-in Find is often the simplest choice when you do not need a repeatable macro or a custom report.
Use this VBA macro to search a category column
The macro below asks for a search term, looks for partial matches in column C, and reports the matching row numbers, business names, and phone numbers. It shows at most ten matching rows in the message box while still reporting the total number of matches. If your worksheet uses different columns, change the column references as explained after the code.
Sub FindPlumberListings()
Dim ws As Worksheet
Dim searchRange As Range
Dim foundCell As Range
Dim firstAddress As String
Dim searchTerm As String
Dim lastRow As Long
Dim matchCount As Long
Dim messageText As String
' Search the active sheet; enter a term such as plumber.
Set ws = ActiveSheet
searchTerm = Trim$(InputBox("Search the service descriptions for:", _
"Find a provider", "plumber"))
If Len(searchTerm) = 0 Then Exit Sub
' Column C contains service descriptions; row 1 contains headers.
lastRow = ws.Cells(ws.Rows.Count, 3).End(xlUp).Row
If lastRow < 2 Then
MsgBox "There are no service descriptions to search.", vbInformation
Exit Sub
End If
Set searchRange = ws.Range("C2:C" & lastRow)
' Find partial, case-insensitive matches among displayed cell values.
Set foundCell = searchRange.Find(What:=searchTerm, _
After:=searchRange.Cells(searchRange.Cells.Count), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not foundCell Is Nothing Then
firstAddress = foundCell.Address
Do
matchCount = matchCount + 1
If matchCount <= 10 Then
messageText = messageText & vbCrLf & "Row " & foundCell.Row & ": " & _
CStr(ws.Cells(foundCell.Row, 1).Value) & " | " & _
CStr(ws.Cells(foundCell.Row, 2).Value)
End If
Set foundCell = searchRange.FindNext(foundCell)
Loop While Not foundCell Is Nothing And foundCell.Address <> firstAddress
End If
If matchCount = 0 Then
MsgBox "No matches were found on " & ws.Name & ".", vbInformation
Else
If matchCount > 10 Then
messageText = messageText & vbCrLf & "(Showing the first 10 matches.)"
End If
MsgBox matchCount & " match(es) found:" & messageText, vbInformation
End If
End Sub
In the code shown as HTML, the symbols `<` and `&` represent the less-than sign and ampersand. When entering the macro in the VBA editor, use the actual VBA operators: write `If lastRow < 2 Then` as `If lastRow < 2 Then`, and use `&` for string concatenation. The editor needs VBA code, not HTML entities.
Install and run the macro
Save a backup copy of the workbook before running a macro. Macros cannot be undone with Ctrl+Z, even when they make changes; this example only reads cells and displays results, but a backup is still sensible when working with important data. Save the working file as an Excel Macro-Enabled Workbook (.xlsm) if you want the macro to remain available in that file.
- Open the workbook and confirm that the intended contact list is on the active worksheet.
- On Windows, press Alt+F11 to open the Visual Basic Editor. On Mac, Option+F11 may open it; keyboard layouts and function-key settings can affect that shortcut. You can also use Developer > Visual Basic when the Developer tab is available.
- In the editor, choose Insert > Module, paste the VBA code into the module, and return to Excel.
- Run the macro from Excel’s macro interface or the Visual Basic Editor. When prompted, enter plumber or another term and review the results.
Excel may block macros based on the file’s source or your organization’s security settings. Only enable macros in workbooks you trust. Do not lower security settings or enable unknown code simply to run a search; use the built-in Find command if you cannot confirm where a macro came from.
How the Find method works
The macro uses Excel’s Range.Find method on a specifically defined range, C2 through the last non-empty cell in column C. Setting LookAt to xlPart means a search for “plumber” can match a longer entry such as “licensed plumber” or “plumber and drain service.” MatchCase set to False makes the search case-insensitive, so “Plumber” and “plumber” are treated alike. LookIn set to xlValues searches the cell’s displayed result rather than its formula text.
Find returns the first matching cell, or Nothing if there is no match. FindNext then moves through subsequent matches. The code remembers the address of the first match and stops when the search wraps back to it; without that stopping condition, a loop could keep cycling through the same results. The macro also specifies its search settings because Excel can retain Find options from earlier searches.
Partial matching is convenient, but it can include unwanted results. For instance, a search for a short fragment might match a different word that contains those letters. If you need a whole-cell match, replace `LookAt:=xlPart` with `LookAt:=xlWhole`. That stricter setting will not match a cell reading “plumber and drain service” when the search term is only “plumber.”
Adapt the macro to your own list
If the category is in column D instead of C, update the last-row calculation and the search range so both point to column D. If names and phone numbers are in different columns, change the two `Cells(foundCell.Row, 1)` and `Cells(foundCell.Row, 2)` references. The numbers represent worksheet columns: 1 is A, 2 is B, 3 is C, and 4 is D. Keep the header-row assumption in mind; if your data starts on row 5, adjust the range start and the test for whether there are data rows.
You can also choose to search a notes column, but a broad notes search may return incidental mentions rather than provider categories. A listing might say “does not provide plumbing work,” for example, and still match the word. Review the complete row before treating a result as a suitable provider. For higher-stakes directories, add structured fields such as trade, service area, and verification date rather than relying on free-form notes alone.
Common problems and practical limits
- No results: Confirm that the active sheet is correct, descriptions are in column C, and the data begins below the header. Check for alternate wording such as “plumbing” or “pipe repair.”
- Only some records appear: The macro searches only the active sheet and only the range in column C. It does not search every worksheet, hidden sheets, or business names in column A.
- A result is not relevant: The code matches text, not meaning. A keyword match does not prove that the business offers the service you need or works in your area.
- The workbook is read-only or macro execution is blocked: You may not have permission to change or run code in that file. Use Find, request an approved copy, or ask the workbook owner or IT administrator for guidance.
A further limitation is that the macro finds the last used row by looking in column C. If descriptions are blank below the last filled category cell, those later rows are outside the search range. If the sheet is a formatted Excel table, a table-based approach can be more resilient when rows are added, but it requires adapting the code to the table’s actual name and column headers.
Alternatives for finding an actual plumber
If you mean a plumber to hire rather than a record in Excel, use a current local directory, a trusted referral, or an applicable professional or government directory. Confirm that the provider serves your address, handles the particular job, and has any licence or registration required where you live. Requirements vary by location and by type of work, so a search result alone is not proof of credentials.
For an urgent leak or loss of essential service, contact a local emergency plumbing provider or the relevant utility when the issue may involve its equipment. Before authorizing work, ask what the call-out charge covers, whether parts and additional labour are separate, and whether the provider can give a written estimate. These checks are separate from VBA: a spreadsheet can organize names and notes, but it cannot verify current availability, pricing, or service quality.
Frequently Asked Questions
Can VBA search for a plumber on the internet?
No. The macro searches cell contents in the active Excel worksheet. Finding current local services requires an online directory or other up-to-date source; VBA would need separate, deliberately built web functionality and an appropriate data source.
How do I search for “plumber” in every worksheet?
Use Ctrl+F on Windows or Command+F on Mac and change the search scope to the workbook in the Find options. The sample macro searches only the active sheet. Extending it to every worksheet requires looping through the workbook’s worksheets and handling each sheet’s results.
Can the macro search business names instead of service categories?
Yes. Change the search range from column C to column A, including the last-row calculation if names are the more complete column. The example still reports the values in columns A and B, so adjust those output fields if your contact layout differs.
Why does a search for plumber find “plumbers” too?
The macro uses a partial match, so it finds the search text anywhere within a cell. Use a whole-cell match for exact contents, or search a carefully maintained category field. Whole-cell matching will exclude longer descriptions containing the word.
Do I need VBA for a simple search?
No. Ctrl+F on Windows or Command+F on Mac is usually quicker for occasional searches. VBA is most useful when you repeat the same lookup, want a tailored summary, or need to incorporate the search into a larger workbook process.
Related
- Can You Open a Corrupted Excel File Online for Free?
- OneDrive Excel File Corrupted? Practical Repair Steps
- Excel Shortcut Keys: Essential Windows and Mac Keys
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Find LookIn: What It Means and How to Use ItIn Excel VBA, LookIn is an argument of the Range.Find method that tells Excel what kind of content…
- Excel VBA Find Text in a Range: Code and Examples ExplainedTo find text in an Excel range with VBA, use the range’s Find method and check whether it…
- Excel VBA New Line in a String: Practical ExamplesTo add a new line to a string in Excel VBA, join the text with a newline constant:…
- VBA ArrayList: How to Create and Use It in Excel VBAIn VBA, an ArrayList is a resizable, zero-based list that you can create on Windows with CreateObject("System.Collections.ArrayList"). It…
- Excel VBA Active Worksheet Reference ExplainedIn Excel VBA, use ActiveSheet to refer to the sheet currently active in the active workbook. For a…
- Optimize Copy Paste VBA for Faster Excel WorkbooksTo optimize copy-and-paste in Excel VBA, avoid selecting cells and using the clipboard when you only need to…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.