{"id":16796,"date":"2023-11-08T09:27:04","date_gmt":"2023-11-08T09:27:04","guid":{"rendered":"https:\/\/officetuts.net\/excel\/?p=16796"},"modified":"2024-02-19T14:59:59","modified_gmt":"2024-02-19T14:59:59","slug":"select-rows-with-specific-text-in-excel-vba","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/","title":{"rendered":"How to Select Rows With Specific Text in Excel VBA"},"content":{"rendered":"\n

Microsoft Excel provides a powerful platform for analyzing data, and sometimes, you may need to work with rows that contain specific text. Automating this process with VBA can save you time and effort, especially when dealing with large datasets. This tutorial will guide you through selecting rows in Excel that contain specified text using VBA.<\/p>\n\n\n\n

Example<\/h2>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Steps to Select Rows with Specific Text Using VBA<\/h2>\n\n\n\n

To select rows based on specific text in Excel using VBA, follow these steps:<\/p>\n\n\n\n

Step 1: Define the Range and the Text to Search For<\/h3>\n\n\n\n

Identify the worksheet and the range of cells you want to search. Also, define the text you’re looking for. In our example, we’ll search for the text “SpecificText”.<\/p>\n\n\n\n

Step 2: Loop Through Each Row in the Range<\/h3>\n\n\n\n

Use a For<\/strong> loop to iterate through each row in the specified range.<\/p>\n\n\n\n

Step 3: Check if the Row Contains the Specific Text<\/h3>\n\n\n\n

During the loop, use the InStr<\/strong> function to check if the specific text is present in any cell of the row.<\/p>\n\n\n\n

Step 4: Select the Row if the Text is Found<\/h3>\n\n\n\n

If the text is found within a row, use the Select<\/strong> method to select the entire row.<\/p>\n\n\n\n

Example VBA Code<\/h2>\n\n\n\n

Here\u2019s the full code that you can use as a reference to select rows with specific text:<\/p>\n\n\n\n

Sub SelectRowsWithSpecificText()\r\n    Dim ws As Worksheet\r\n    Set ws = ThisWorkbook.Sheets(\"Sheet1\")\r\n    Dim searchRange As Range\r\n    Set searchRange = ws.Range(\"A1:A100\")\r\n    Dim cell As Range\r\n    Dim searchText As String\r\n    searchText = \"SpecificText\"\r\n    \r\n    Dim selectedRange As Range ' Create a Range object to store all matching rows\r\n    \r\n    For Each cell In searchRange\r\n        If InStr(1, cell.Value, searchText) > 0 Then\r\n            If selectedRange Is Nothing Then\r\n                ' Initialize the selectedRange with the first matching row\r\n                Set selectedRange = cell.EntireRow\r\n            Else\r\n                ' Add subsequent matching rows to the selectedRange\r\n                Set selectedRange = Union(selectedRange, cell.EntireRow)\r\n            End If\r\n        End If\r\n    Next cell\r\n    \r\n    ' Select all the matching rows at once\r\n    If Not selectedRange Is Nothing Then\r\n        selectedRange.Select\r\n    End If\r\nEnd Sub\r<\/code><\/pre>\n\n\n\n

When executing this script, replace “Sheet1” with the name of your worksheet and adjust the search range (“A1:A100”) to your desired range. Also, replace “SpecificText” with the actual text you’re looking for.<\/p>\n\n\n\n

Result<\/h2>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Conclusion<\/h2>\n\n\n\n

In this tutorial, you’ve learned how to write a VBA macro to select rows with specific text in Excel. This method is particularly useful when dealing with large datasets where manual searching and selection are impractical. You can modify the provided code for different scenarios, adjusting the range or search criteria as needed.<\/p>\n\n\n\n

Remember, VBA can extend the functionality of your Excel workbooks, automating repetitive tasks and increasing your productivity. Excel VBA is a robust tool, but care should be taken when using it to ensure you are manipulating data as intended.<\/p>\n","protected":false},"excerpt":{"rendered":"

Microsoft Excel provides a powerful platform for analyzing data, and sometimes, you may need to work with rows that contain specific text. Automating…<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"yoast_head":"\nHow to Select Rows With Specific Text in Excel VBA<\/title>\n<meta name=\"description\" content=\"Learn how to select rows in Excel that contain specific text using VBA. Automate this process to save time and effort when dealing with large datasets.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Select Rows With Specific Text in Excel VBA\" \/>\n<meta property=\"og:description\" content=\"Learn how to select rows in Excel that contain specific text using VBA. Automate this process to save time and effort when dealing with large datasets.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-08T09:27:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-19T14:59:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png\" \/>\n<meta name=\"author\" content=\"Tomasz Decker\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tomasz Decker\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/\"},\"author\":{\"name\":\"Tomasz Decker\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/10baa1deb54627da5d59757d6924066e\"},\"headline\":\"How to Select Rows With Specific Text in Excel VBA\",\"datePublished\":\"2023-11-08T09:27:04+00:00\",\"dateModified\":\"2024-02-19T14:59:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/\"},\"wordCount\":356,\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png\",\"articleSection\":[\"vba\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/\",\"url\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/\",\"name\":\"How to Select Rows With Specific Text in Excel VBA\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png\",\"datePublished\":\"2023-11-08T09:27:04+00:00\",\"dateModified\":\"2024-02-19T14:59:59+00:00\",\"description\":\"Learn how to select rows in Excel that contain specific text using VBA. Automate this process to save time and effort when dealing with large datasets.\",\"breadcrumb\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#primaryimage\",\"url\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png\",\"contentUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png\",\"width\":315,\"height\":144},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/officetuts.net\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Select Rows With Specific Text in Excel VBA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/officetuts.net\/excel\/#website\",\"url\":\"https:\/\/officetuts.net\/excel\/\",\"name\":\"\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/officetuts.net\/excel\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\",\"name\":\"Tomasz Decker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"caption\":\"Tomasz Decker\"},\"logo\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\"},\"description\":\"Spreadsheet and Python enthusiast.\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/10baa1deb54627da5d59757d6924066e\",\"name\":\"Tomasz Decker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d92ef5a1e35bf0d44baf479313c76713?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d92ef5a1e35bf0d44baf479313c76713?s=96&d=mm&r=g\",\"caption\":\"Tomasz Decker\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Select Rows With Specific Text in Excel VBA","description":"Learn how to select rows in Excel that contain specific text using VBA. Automate this process to save time and effort when dealing with large datasets.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/","og_locale":"en_US","og_type":"article","og_title":"How to Select Rows With Specific Text in Excel VBA","og_description":"Learn how to select rows in Excel that contain specific text using VBA. Automate this process to save time and effort when dealing with large datasets.","og_url":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/","article_published_time":"2023-11-08T09:27:04+00:00","article_modified_time":"2024-02-19T14:59:59+00:00","og_image":[{"url":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png"}],"author":"Tomasz Decker","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Tomasz Decker","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#article","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/"},"author":{"name":"Tomasz Decker","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/10baa1deb54627da5d59757d6924066e"},"headline":"How to Select Rows With Specific Text in Excel VBA","datePublished":"2023-11-08T09:27:04+00:00","dateModified":"2024-02-19T14:59:59+00:00","mainEntityOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/"},"wordCount":356,"publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#primaryimage"},"thumbnailUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png","articleSection":["vba"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/","url":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/","name":"How to Select Rows With Specific Text in Excel VBA","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#primaryimage"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#primaryimage"},"thumbnailUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png","datePublished":"2023-11-08T09:27:04+00:00","dateModified":"2024-02-19T14:59:59+00:00","description":"Learn how to select rows in Excel that contain specific text using VBA. Automate this process to save time and effort when dealing with large datasets.","breadcrumb":{"@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#primaryimage","url":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png","contentUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/11\/select-rows-with-specific-text-in-excel-vba.png","width":315,"height":144},{"@type":"BreadcrumbList","@id":"https:\/\/officetuts.net\/excel\/vba\/select-rows-with-specific-text-in-excel-vba\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/officetuts.net\/excel\/"},{"@type":"ListItem","position":2,"name":"How to Select Rows With Specific Text in Excel VBA"}]},{"@type":"WebSite","@id":"https:\/\/officetuts.net\/excel\/#website","url":"https:\/\/officetuts.net\/excel\/","name":"","description":"","publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/officetuts.net\/excel\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42","name":"Tomasz Decker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","caption":"Tomasz Decker"},"logo":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/"},"description":"Spreadsheet and Python enthusiast."},{"@type":"Person","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/10baa1deb54627da5d59757d6924066e","name":"Tomasz Decker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d92ef5a1e35bf0d44baf479313c76713?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d92ef5a1e35bf0d44baf479313c76713?s=96&d=mm&r=g","caption":"Tomasz Decker"}}]}},"_links":{"self":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/16796"}],"collection":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/comments?post=16796"}],"version-history":[{"count":2,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/16796\/revisions"}],"predecessor-version":[{"id":16960,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/16796\/revisions\/16960"}],"wp:attachment":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/media?parent=16796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/categories?post=16796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/tags?post=16796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}