how to Delete Rows Based On Conditions in excel VBA?
Tags: todeleterowsbasedonc, vbamacros
Published: 2021-09-27 07:52:56

---
title: how to Delete Rows Based On Conditions in excel VBA?
published: true
date: 2021-09-20 09:54:42 UTC
tags: ToDeleteRowsBasedOnC,VBAMacros
canonical_url: https://geekexcel.com/how-to-delete-rows-based-on-conditions-in-excel-vba/
---

In this tutorial, we will guide you on how to ** delete rows based on conditions**  in Excel Office VBA. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, you need to  **create a sample data**  with **year, product and sales**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Sample-data-26.png)<figcaption>Sample data</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```

Sub DeleteRow()
With Sheet1.Cells(1).CurrentRegion.Columns(2)
.AutoFilter 1, "<>Product B"
.EntireRow.Delete
End With
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-58.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-33.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive the  **output ** in the  **Microsoft Excel**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Output-26.png)<figcaption>Output</figcaption>

## A Brief Synopsis

We hope that this tutorial gives you guidelines on how to ** delete rows based on conditions**  in Excel Office VBA. Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Read Also:**

- **[How to use the XNPV function in Excel office 365?](https://geekexcel.com/how-to-use-the-xnpv-function-in-excel-office-365/)**
- **[Excel Formulas to Highlight the Cells that End with Given Value!!](https://geekexcel.com/excel-formulas-to-highlight-cells-end-with/)**
- **[Excel Shortcut for “Select to End of Cell” in the Worksheet!!](https://geekexcel.com/quick-excel-shortcut-for-select-to-end-of-cell-in-a-worksheet/)**
- **[Excel Shortcuts: Delete to the End of Line in the Spreadsheet!!](https://geekexcel.com/shortcuts-for-delete-to-the-end-of-line-in-ms-excel-365/)**
- **[Excel Formulas for Counting Cells that End with certain character or text!!](https://geekexcel.com/excel-formulas-for-counting-cells-that-end-with-certain-character-or-text/)**