search
HomeSoftware TutorialOffice SoftwareHow to delete rows in Excel using shortcuts or VBA macro

This article introduces various ways to delete rows based on cell values ​​in Excel. You will find hotkeys and Excel VBA codes in this article. You can delete rows automatically, or use standard lookup options in combination with useful shortcut keys.

Excel is an ideal tool for storing frequently changing data. However, updating a table after some changes can take a lot of time. Tasks can be as simple as removing all empty lines in Excel. Alternatively, you may need to find and delete duplicate data. One thing we are sure is that no matter the details are increased or decreased, you are always looking for the best solution to help you save time on your current job.

For example, you have a market where different suppliers sell their products. For some reason one of the vendors closed their business and now you need to delete all rows containing that vendor name, even if they are in a different column.

In this article, you will find Excel VBA codes and shortcuts that delete rows based on specific text or values. You will see how to easily find and select necessary information before deleting it. If your task is not deleting but adding rows, you can find out how to do it in "The Fastest Way to Insert Multiple Lines in Excel".

The fastest Excel shortcut key to delete rows in tables ------------------------------------------------------------------------------------------------------------------

If you want to use the fastest way to delete multiple rows based on cell values, you need to select those rows correctly first.

To select a row, you can highlight adjacent cells with the desired value and press Shift Space, or select the desired non-adjacent cells while holding down the Ctrl key.

You can also use the Line Number button to select the entire row. You will see the highlighted number of rows next to the last button.

How to delete rows in Excel using shortcuts or VBA macro

Once you have selected the necessary rows, you can quickly delete them using Excel's "Delete Rows" shortcut. Below you will find how to delete the selected row, whether you have a standard data table, or a table with data to the right of the table.

Delete rows from the entire table

If you have a simple Excel list without additional information on the right, you can use the Delete Line Shortcut key to delete the line in 2 simple steps:

  1. Select the row you want to delete.
  2. Press Ctrl - (minus sign on the primary keyboard) hotkey.

You will see the unused rows disappear immediately.

hint. You can highlight only the range containing the values ​​you want to delete. Then use the shortcut Ctrl - (minus sign on the primary keyboard) to get the standard Excel delete dialog box, allowing you to select the entire row radio button, or any other delete options you may need.

How to delete rows in Excel using shortcuts or VBA macro

If there is data on the right side of the table, delete the row

Ctrl - (minus sign on the primary keyboard) Excel shortcut keys are the fastest way to delete rows. However, if you have any data on the right side of your main table, as shown in the screenshot below, it may delete the rows and take away the details you need to keep.

How to delete rows in Excel using shortcuts or VBA macro

If this is the case, you need to format the data as an Excel table first.

  1. Press Ctrl T, or go to the Start tab -> Format as table and select the style that suits you best. How to delete rows in Excel using shortcuts or VBA macro

    Format as table button " title="Go to Start tab -> Format as table button " width="451" height="186"> You will see the Create Table dialog box that you can use to highlight the necessary ranges.

    How to delete rows in Excel using shortcuts or VBA macro

  2. Now that your list is formatted, select the range in the table that contains the values ​​or rows you want to delete. How to delete rows in Excel using shortcuts or VBA macro

    Notice. Make sure you do not use the row button to select the entire row.

  3. Press Ctrl - (minus sign on the primary keyboard) to delete unwanted data in the table. The additional information on the right will remain the same.

Hope you find this "Delete Line" shortcut key helpful. Continue reading to find the Excel VBA code used to delete rows and learn how to eliminate data based on specific cell text.

Delete rows containing specific text in a single column

If the items of the row you are deleting appear only in one column, the following steps will guide you how to delete rows containing such values.

  1. First, you need to apply filtering to the table. To do this, navigate to Excel's Data tab and click the Filter icon. How to delete rows in Excel using shortcuts or VBA macro
  2. Filter columns containing deleted values ​​as needed. Click the arrow icon next to the column containing the desired item. Then uncheck the Select All option and select the check box next to the correct value. If the list is long, just enter the necessary text in the search field. Then click OK to confirm. How to delete rows in Excel using shortcuts or VBA macro
  3. Select the filtered cell in the row you want to delete. There is no need to select the entire row.
  4. Right-click the highlighted range and select the Delete Row option from the menu list. How to delete rows in Excel using shortcuts or VBA macro

Finally, click the filter icon again to clear it and you will see the rows containing these values ​​disappear from your table.

How to delete rows in Excel based on cell color

The filter option allows the data to be sorted by the color of the cell. You can use it to delete all rows containing specific background colors.

  1. Apply filters to the table. Go to Excel's Data tab and click the Filter icon. How to delete rows in Excel using shortcuts or VBA macro
  2. Click the arrow next to the desired column name to enter Filter by color and select the correct cell color. Click OK and you will see all the highlighted cells appear at the top. How to delete rows in Excel using shortcuts or VBA macro
  3. Select the filtered colored cells, right-click them and select the Delete Row option from the menu. How to delete rows in Excel using shortcuts or VBA macro

That's it! Rows containing cells of the same color are deleted immediately.

Delete rows containing specific text in different columns

If the values ​​you want to delete are scattered in different columns, sorting can complicate the task. Below you will find a useful trick to delete rows based on cells containing specific values ​​or text. From my table below, I want to delete all rows containing January and it appears in 2 columns.

  1. First search and select the cells containing the desired value by using the Find and Replace dialog box. Click Ctrl F to run it. hint. You can find the same dialog box in the Start tab -> Find and Select and select the Find option from the drop-down list.

    How to delete rows in Excel using shortcuts or VBA macro

    Find and select and select the search option " title="Go to the Start tab -> Find and select and select and select the search option " width="319" height="173">

  2. Enter the desired value in the Find Content field and select any necessary additional options. Then press Find all to view the results. How to delete rows in Excel using shortcuts or VBA macro

  3. The results will appear in the Find and Replace window. How to delete rows in Excel using shortcuts or VBA macro

    Press and hold the Ctrl key in the window to select the found value. You will automatically highlight the found values ​​in the table.

    How to delete rows in Excel using shortcuts or VBA macro

  4. Now navigate to the Start tab -> Delete -> Delete sheet rows . How to delete rows in Excel using shortcuts or VBA macro

    Delete -> Delete Worksheet Rows" title="Navigate to Start Tab-> Delete -> Delete Worksheet Rows" width="324" height="179"> Prompt. You can delete rows containing selected values ​​by pressing Ctrl - (minus sign on the motherboard) and selecting the radio button to complete row .

Look! Unwanted lines have been deleted.

Excel VBA macros to delete rows or delete every other row

If you are always looking for solutions that automate this or that Excel routine, use the macro below to simplify your delete row task. In this section you will find 2 VBA macros that will help you delete rows containing selected cells or delete every other row in Excel according to your settings.

The macro RemoveRowsWithSelectedCells will delete all rows containing at least one highlighted cell.

The macro RemoveEveryOtherRow , as the name implies, will help you remove every other row/third row, etc. according to your settings. It will delete rows from the current mouse cursor position until the table ends.

If you don't know how to insert macros, feel free to check out How to Insert and Run VBA Code in Excel.

Sub RemoveRowsWithSelectedCells() Dim rngCurCell, rng2Delete As Range Application.ScreenUpdating = False Application.Calculation = xlCalculationManual For Each rngCurCell In Selection If Not rng2Delete Is Nothing Then Set rng2Delete = Application.Union(rng2Delete, _ ActiveSheet.Cells(rngCurCell.Row, 1)) Else Set rng2Delete = rngCurCell End If Next rngCurCell If Not rng2Delete Is Nothing Then rng2Delete.EntireRow.Delete End If Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic End Sub Sub RemoveEveryOtherRow() Dim rowNo, rowStart, rowFinish, rowStep As Long Dim rng2Delete As Range rowStep = 2 rowStart = Application.Selection.Cells(1, 1).Row rowFinish = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row Application.ScreenUpdating = False Application.Calculation = xlCalculationManual For rowNo = rowStart To rowFinish Step rowStep If Not rng2Delete Is Nothing Then Set rng2Delete = Application.Union(rng2Delete, _ ActiveSheet.Cells(rowNo, 1)) Else Set rng2Delete = ActiveSheet.Cells(rowNo, 1) End If Next If Not rng2Delete Is Nothing Then rng2Delete.EntireRow.Delete ' Hide every other line'rng2Delete.EntireRow.Hidden = True End If Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic End Sub Tip. If your task is to color every other row/third row, etc. with different colors, you will find the steps in Alternate Row Color and Column Coloring in Excel (Ranning Rows and Columns).

In this article, I describe how to delete rows in Excel. Now you have several useful VBA macros to delete selected rows, you know how to delete every other row and how to use find and replace to help you search and select all rows containing the same value, and then eliminate them. Hope the above suggestions simplify your work in Excel and give you more free time to enjoy this final summer day. I wish you happiness and excellence in Excel!

The above is the detailed content of How to delete rows in Excel using shortcuts or VBA macro. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to do case-sensitive Vlookup  in Excel – formula examplesHow to do case-sensitive Vlookup in Excel – formula examplesMay 16, 2025 am 09:42 AM

This tutorial explains how to make Excel's VLOOKUP function case sensitive, shows some other formulas that recognize text case, and points out the advantages and limitations of each function. I think every user using Excel knows what the function in Excel is doing vertical lookup. That's right, it's VLOOKUP. However, few people know that Excel's VLOOKUP is case-insensitive, meaning it treats lowercase and uppercase letters as the same characters. Here is a quick example showing VLOOKUP's ability to be insensitive to text. Suppose you enter "bill" in cell A2 and "Bill" in cell A4.

Excel INDEX MATCH vs. VLOOKUP - formula examplesExcel INDEX MATCH vs. VLOOKUP - formula examplesMay 16, 2025 am 09:22 AM

This tutorial shows how to use INDEX and MATCH functions in Excel and why it is better than VLOOKUP. In recent articles, we strive to explain the basics of VLOOKUP functions to beginners and provide more complex examples of VLOOKUP formulas for advanced users. Now, I'll try not just to persuade you not to use VLOOKUP, but to at least show an alternative to doing vertical lookups in Excel. "Why do I need this?" you might ask. Because VLOOKUP has many limitations, it may prevent you from getting the desired result in many cases. On the other hand, the INDEX MATCH combination is more flexible and has many excellent features that make it in

How to delete rows in Excel using shortcuts or VBA macroHow to delete rows in Excel using shortcuts or VBA macroMay 16, 2025 am 09:03 AM

This article introduces various ways to delete rows based on cell values ​​in Excel. You will find hotkeys and Excel VBA codes in this article. You can delete rows automatically, or use standard lookup options in combination with useful shortcut keys. Excel is an ideal tool for storing frequently changing data. However, updating a table after some changes can take a lot of time. Tasks can be as simple as removing all empty lines in Excel. Alternatively, you may need to find and delete duplicate data. One thing we are sure is that no matter the details are increased or decreased, you are always looking for the best solution to help you save time on your current job. For example, you have a market where different suppliers sell their products. For some reason, one of them

How to convert number to text in Excel - 4 quick waysHow to convert number to text in Excel - 4 quick waysMay 15, 2025 am 10:10 AM

This tutorial shows how to convert numbers to text in Excel 2016, 2013, and 2010. Learn how to do this using Excel's TEXT function and use numbers to strings to specify the format. Learn how to change the format of numbers to text using the Format Cell… and Text to Column options. If you use an Excel spreadsheet to store long or short numbers, you may want to convert them to text one day. There may be different reasons to change the number stored as a number to text. Here is why you might need to have Excel treat the entered number as text instead of numbers: Search by part rather than the whole number. For example, you might want to find all numbers containing 50, such as 501

How to make a dependent (cascading) drop-down list in ExcelHow to make a dependent (cascading) drop-down list in ExcelMay 15, 2025 am 09:48 AM

We recently delved into the basics of Excel Data Validation, exploring how to set up a straightforward drop-down list using a comma-separated list, cell range, or named range.In today's session, we'll delve deeper into this functionality, focusing on

How to create drop down list in Excel: dynamic, editable, searchableHow to create drop down list in Excel: dynamic, editable, searchableMay 15, 2025 am 09:47 AM

This tutorial shows simple steps to create a drop-down list in Excel: Create from cell ranges, named ranges, Excel tables, other worksheets. You will also learn how to make Excel drop-down menus dynamic, editable, and searchable. Microsoft Excel is good at organizing and analyzing complex data. One of its most useful features is the ability to create drop-down menus that allow users to select items from predefined lists. The drop-down menu allows for faster, more accurate and more consistent data entry. This article will show you several different ways to create drop-down menus in Excel. - Excel drop-down list - How to create dropdown list in Excel - From the scope - From the naming range

Convert PDF to Excel manually or using online convertersConvert PDF to Excel manually or using online convertersMay 15, 2025 am 09:40 AM

The PDF format, known for its ability to display documents independently of the user's software, hardware, or operating system, has become the standard for electronic file sharing.When requesting information, it's common to receive a well-formatted P

How to convert Excel files to PDFHow to convert Excel files to PDFMay 15, 2025 am 09:37 AM

This short tutorial describes 4 possible ways to convert Excel files to PDF - using Excel's Save As feature, Adobe software, online Excel to PDF converter, and desktop tools. Converting an Excel worksheet to a PDF is usually necessary if you want other users to be able to view your data but can't edit it. You may also want to convert Excel spreadsheets to PDF format for use in media toolkits, presentations, and reports, or create a file that all users can open and read even if they don't have Microsoft Excel installed, such as on a tablet or phone. Today, PDF is undoubtedly one of the most popular file formats. According to Google

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.