How to Delete Empty Columns through VBA in Microsoft Excel?
Tags: todeleteemptycolumns, vbamacros
Published: 2021-09-14 12:40:32

---
title: How to Delete Empty Columns through VBA in Microsoft Excel?
published: true
date: 2021-09-13 14:13:08 UTC
tags: ToDeleteEmptyColumns,VBAMacros
canonical_url: https://geekexcel.com/how-to-delete-empty-columns-through-vba-in-microsoft-excel/
---

In this tutorial, we will guide you on  **how to delete empty columns through VBA in Microsoft Excel**. 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, 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 need to  **insert a module**.
- After that, you have to go to  **insert menu**  and click on  **procedure** , where you will get the procedure if you don’t know how it should be started the  **macro**.
- You have to  **copy and paste**  the following code.

```
Sub Delete_Columns()
Dim C As Integer
C = ActiveSheet.Cells.SpecialCells(xlLastCell).Column
Do Until C = 0
If WorksheetFunction.CountA(Columns(C)) = 0 Then
Columns(C).Delete
End If
C = C - 1
Loop
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-34.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/Save-the-Code-33.png)<figcaption>Save the Code</figcaption>

- Finally, you will get  **output ** as given below in the  **Microsoft Excel**.

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

## Closure

We hope that this short tutorial gives you guidelines on **how to delete empty columns through VBA in Microsoft Excel. ** 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/) **!!**

**Keep Reading:**

- **[Options in Quick Access Toolbar in Microsoft Excel 365](https://geekexcel.com/options-in-quick-access-toolbar-in-microsoft-excel-365/)**
- **[What is a Name Box and Its Features in Microsoft Excel 365?](https://geekexcel.com/what-is-a-name-box-and-its-features-in-microsoft-excel-365/)**
- **[How to Convert Excel Files to PDF in Microsoft Excel 365](https://geekexcel.com/how-to-convert-excel-files-to-pdf-in-microsoft-excel-365/)**
- **[How to Write To A Word File Using Macros (VBA) in Excel Office 365?](https://geekexcel.com/how-to-write-to-a-word-file-using-macros-vba-in-excel-office-365/)**
- **[What is CreateObject Method in VBA & How to use CreateObject Method in Excel?](https://geekexcel.com/what-is-createobject-method-in-vba-how-to-use-createobject-method-in-excel/)**