Sometimes you may need to select an entire row based on any specific data in a cell of that row. In this article, we’ll show you 4 easy and simple ways to select a row in Excel if a cell contains specific data.
How to Select Row in Excel If Cell Contains Specific Data: 4 Simple Ways
For demonstration, we have a dataset of the Owners of different books.
Method 1 – Utilize the Filter Feature to Select a Row Based on Specific Data in Excel
- Select the entire dataset and go to Home, then to Editing.
- Go to Sort & Filter and choose Filter.
- You’ll get small downward arrows next to the row headers.
- Click on the arrow for Owner.
- This will open a dropdown menu.
- Select Harold from this dropdown menu and click on OK.
- You will see only the rows that contain Harold.
- Select those rows manually by holding Ctrl and dragging over them.
Method 2 – Select a Row If Cell Contains Specific Text Using Conditional Formatting
- Select your entire dataset and go to Home, then to Conditional Formatting.
- Click on Highlight Cells Rules and select Text that Contains.
- You will get a dialog window named Text That Contains.
- Type the data based on which row will be selected in the box Format cells that contain the text. We’ve typed Ana.
- In the with section, select your preferred formatting style. We’ve selected Light Red Fill with Dark Red Text.
- Click OK.
- You will see the cells which contain the data highlighted.
- You can select the rows by pressing Ctrl and clicking on the row numbers of the highlighted cells.
Method 3 – Applying the Find & Select Feature
- Select your entire dataset and go to Home and Editing.
- Go to Find & Select and choose Find.
- You will see a window named Find and Replace.
- Type the data which will be selected in the Find what box. We’ve typed Harold.
- Click on Find All.
- You will see the cells that have that specific data shown at the bottom of the Find and Replace window.
- Select the cells and close the Find and Replace window.
- You will see the cells which contain the Harold selected.
- Select the entire rows by holding Ctrl and clicking on the row numbers of the cells.
Method 4 – Incorporating VBA to Select a Row
- Press Alt + F11 to open the VBA window.
- From the left panel of this window, right-click on the sheet name and go to Insert and Module.
- This will open the Module (Code) window. Insert the following code in it.
Sub select_rows_with_given_data()
Dim Rng As Range
Dim myCell As Object
Dim myUnion As Range
Set Rng = Selection
searchdata = InputBox("Please Enter the Search data")
For Each myCell In Rng
If InStr(myCell.Text, searchdata) Then
If Not myUnion Is Nothing Then
Set myUnion = Union(myUnion, myCell.EntireRow)
Else
Set myUnion = myCell.EntireRow
End If
End If
Next
If myUnion Is Nothing Then
MsgBox "The data was not found in the selection"
Else
myUnion.Select
End If
End Sub
- Close the VBA window and select your dataset.
- Go to View and Macro to run the Macro.
- A window named Macro will be opened.
- Select select_rows_with_given_data from the Macro name box and click on Run.
- This will open a custom box.
- In the Please Enter the Search data box, type the specific data and click on OK.
- The code will open a custom box where you can insert the data. If the data is found in your selected cell ranges, the macro will select the entire row. If the data is not found, it will give an error message.
- You will see all the rows that contain the specific data in one of its cells are selected.
Download the Practice Workbook
Related Articles
- How to Select Every Other Row in Excel
- How Do I Quickly Select Thousands of Rows in Excel
- How To Select All Rows to Below in Excel
<< Go Back to Select Row | Rows in Excel | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!