How to Select Row in Excel If Cell Contains Specific Data (4 Ways)

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.

excel select row if cell contains


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.

dataset to select row


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.

selecting filter feature

  • You’ll get small downward arrows next to the row headers.
  • Click on the arrow for Owner.
  • This will open a dropdown menu.

using filter option

  • 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.

result of excel selected row if cell contains specific data


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.

Select Row If Cell Contains Specific Text Using Conditional Formatting

  • 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.

giving input to text that contains box

  • 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.

result of excel select row if cell contains specific text


Method 3 – Applying the Find & Select Feature

  • Select your entire dataset and go to Home and Editing.
  • Go to Find & Select and choose Find.

selecting find and select feature

  • 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.

using find and replace to select text

  • 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.

selected text in find and replace box

  • 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.

selected row having specific text using find and replace


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.

inserting new module in vba window

  • 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

VBA CODE

  • Close the VBA window and select your dataset.
  • Go to View and Macro to run the Macro.

selecting data and opening macro

  • A window named Macro will be opened.
  • Select select_rows_with_given_data from the Macro name box and click on Run.

running macro

  • This will open a custom box.
  • In the Please Enter the Search data box, type the specific data and click on OK.

inserting specific text in custom box

  • 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.

result of excel select row if cell contains using vba


Download the Practice Workbook


Related Articles


<< Go Back to Select Row | Rows in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Prantick Bala
Prantick Bala

PRANTICK BALA is a marine engineer who loves exploring Excel and VBA programming. Programming, to him, is a time-saving tool for efficiently managing data, files, and internet tasks. He is proficient in Rhino3D, Maxsurf, C++, MS Office, AutoCAD, Excel, and VBA and goes beyond the basics. Armed with a B.Sc in Naval Architecture & Marine Engineering from BUET, he has transitioned into the role of a content developer. Beyond his work, find him immersed in books, exploring new... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo