

In this way, the code selects all rows that contain the search string provided by the user. Select’ to select all the rows that have been added to myUnion. To find out if a cell contains the given search string, we used the InStr function. If a cell contains the given search string, we add the entire row of that cell to myUnion (a Range variable containing the range of all rows that we want to select).

We then used a For-each loop to cycle through each cell in the given range ( Rng). In the above code we used the InputBox function to obtain the search string input from the user. You can also use this script and tweak it to suit your own requirements. Now that your required rows are selected you can go ahead and perform whatever actions you need to with them.

Using VBA to Select Rows with Specific Text in Excel Here are two ways to tackle this problem. Given the above data, let us say you want to find and select all the rows that contain the word “ King” in them.
