How To use Wildcard to delete cells through Excel VBA?
Tags: tousewildcardtodelet, vbamacros
Published: 2021-09-17 03:37:02

---
title: How To use Wildcard to delete cells through Excel VBA?
published: true
date: 2021-09-16 02:13:43 UTC
tags: ToUseWildcardToDelet,VBAMacros
canonical_url: https://geekexcel.com/how-to-use-wildcard-to-delete-cells-through-excel-vba/
---

In this tutorial, we will guide you on how to **use the wildcard to delete cells** through Excel 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)**

## Delete Every Cell in A range except Cells Containing “ABC”

- Firstly, you need to **create the sample data cells** in the Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Sample-data-12.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-8-1024x180.png)<figcaption>Select Visual Basic</figcaption>

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

```
Sub DeleteCells()
Dim criteriarange As Range
Dim criteriacell As Range
Set criteriarange = Range("A1:B5")
For Each criteriacell In criteriarange
If Not criteriacell.Value Like "*ABC*" Then
criteriacell.ClearContents
End If
Next criteriacell
End Sub

```

- After that, 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-42.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-23.png)<figcaption>Run the Code</figcaption>

- After that, you need to **select the data range A1:B5.**
- Finally, you will receive the **output** with **deleted cells** as given below.

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

## A Brief Synopsis

Here, we have explained the step-by-step procedure on how to **use the wildcard to delete cells** through Excel VBA. Make use of this. Please share your worthwhile  **feedback**  in the below  **comment**  section. To learn more, check out our website **[Geek Excel](https://geekexcel.com/)!!**

**Read Ahead:**

- **[Excel Formulas to Highlight the Cells Between Two Dates!!](https://geekexcel.com/excel-formulas-to-highlight-the-cells-between-two-dates/)**
- **[Extract the Missing Values through Excel VBA](https://geekexcel.com/how-to-extract-the-missing-values-through-excel-vba/)**
- **[Excel Formulas to Find the Missing Values From a list!!](https://geekexcel.com/excel-formulas-find-missing-values-from-a-list/)**
- **[Formulas to Find the Missing Value from a Range!!](https://geekexcel.com/excel-formulas-find-missing-value/)**
- **[Excel Formulas to Highlight the Missing Values ~ Easy Tutorial!!](https://geekexcel.com/excel-formulas-to-highlight-the-missing-values-easy-tutorial/)**