How to Delete Columns with Specific Text in Excel (3 Methods)

To demonstrate our methods we’ll use the dataset below, namely a Monthly Itinerary for a Group of People.

excel delete columns with specific text

We used the Microsoft Office 365 version here, but you may use any other version at your convenience.


Method 1 – Using Find & Replace Feature

Let’s delete the column that contains Ohio using Excel’s dedicated Find & Replace feature.

Steps:

  • Go to Home > Find & Select > Find.

Using Find & Select Feature

Using Find & Select Feature

A Find and Replace dialog box will appear.

  • In the Find What box, type the word you are looking for (Ohio).
  • Click Find All.
  • Press Ctrl + A to select all the values that are returned.
  • Click Close.

Using Find & Select Feature

All the cells containing Ohio (here two cells contain the word) will be selected as below.

Using Find & Select Feature

  • Select Home > Delete > Delete Sheet Columns.

Using Find & Select Feature

All the columns containing Ohio are deleted.

Using Find & Select Feature

Read More: How to Delete Multiple Columns in Excel with Condition


Method 2 – Using Keyboard Shortcut

Steps:

  • Select all cells containing Ohio by holding down the Ctrl key while clicking on them.
  • Right-click on your mouse.
  • Select Delete from the Context Menu.

Utilizing Keyboard Shortcut

  • A small Delete dialog box will appear.
  • Select Entire column.
  • Click OK.

Utilizing Keyboard Shortcut

The output is given below.

Utilizing Keyboard Shortcut


Method 3 – Using VBA Code

This method is the most efficient for larger datasets.

Steps:

  • Go to the Developer tab > Click on Visual Basic.

Incorporating VBA Code

  • Go to the Insert tab > Select Module.

Incorporating VBA Code

  • Copy and Paste the following VBA code into the Module window:
Sub DeleteColumnswithSpecificValue()
Dim cell As Range
For Each cell In Range("B2:F9")
If cell.Value = "Ohio" Then
cell.EntireColumn.Delete

End If

Next cell
End Sub
  • Close the VBA window.

Code Breakdown:

  • We select the lookup range.
  • Then we iterate through the range, and delete the Entire Column containing any cells which match the criterion Ohio.

Incorporating VBA Code

  • Go to Developer > Macros.

Incorporating VBA Code

This will open the Macro Name dialog box.

  • Select our function (DeleteColumnswithSpecificValue).
  • Click the Run button.

Incorporating VBA Code

The final output is given below.

Incorporating VBA Code


How to Delete Multiple Columns That Are Blank in Excel

Steps:

  • Select the range of data.

How to Delete Multiple Columns That Are Blank

  • Go to Home > Find & Select > Go To Special.

How to Delete Multiple Columns That Are Blank

  • Select Blanks and click OK.

How to Delete Multiple Columns That Are Blank

All the blank cells will be selected.

How to Delete Multiple Columns That Are Blank

  • Click Home > Delete > Delete Sheet Columns.

How to Delete Multiple Columns That Are Blank

The result is below.

How to Delete Multiple Columns That Are Blank

Read More: How to Delete Blank Columns in Excel


How to Delete Rows Without Specific Text in Excel

Steps:

  • Press Alt + F11 to open the Microsoft Visual Basic window.
  • Go to Insert > Module to open a blank module.

How to Delete Rows Without Specific Text in Excel

  • Copy and paste the following code into the module:
Sub DelRowsNotContainSpecificTexr()
    Set findRange = Application.Selection
    Set findRange = Application.InputBox("Select one Range which contain texts that you want to delete rows based on", "DelRowsNotContainCertainText", findRange.Address, Type:=8)
    findTexr = Application.InputBox("Please type a certain text", "DelRowsNotContainSpecificTexr", "", Type:=2)
    For i = findRange.Rows.Count To 1 Step -1
        Set findRow = findRange.Rows(i)
        Set findCell = findRow.Find(findTexr, LookIn:=xlValues)
        If findCell Is Nothing Then
        findRow.Delete
        End If
    Next
End Sub

How to Delete Rows Without Specific Text in Excel

  • Press the F5 key to run the code.

A dialog box opens.

  • Select the range in which you wish to do your task and click OK.

How to Delete Rows Without Specific Text in Excel

Another dialog box opens.

  • Enter the name of your word (rows containing this word will not be deleted).
  • Click OK.

How to Delete Rows Without Specific Text in Excel

The output is as follows.

How to Delete Rows Without Specific Text in Excel


Download Practice Workbook


Related Articles


<< Go Back to Delete Columns | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mohammad Shah Miran
Mohammad Shah Miran

Mohammad Shah Miran has a professional background spanning over a year at Softeko. Initially starting as an Excel and VBA writer, he authored more than 50 articles for the ExcelDemy project. Currently, Miran is engaged in the LinuxSimply project as a Linux content developer, completed over 40 articles. His analytical approach extends across various domains, including Excel, VBA, Bash scripting, Linux, data analysis, and Python programming. In his leisure time, Miran enjoys watching movies and series or listening... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo