This VBA Code allows you to delete the empty column which from a given range
You can use the code in Excel for mac & windows
- Copy the below VBA Code by clicking on the copy box
- Open Microsoft Visual Basic for Applications window Developer Ribbon Tab > Visual Basic (Shortcut keys as follows for mac & windows)
- mac users fn + ⌥ [option] + F11
- windows users Alt + F11
- From the menu bar select Insert > Module and insert new Modules
- Paste the code into the module.
Note: It is always to take a back-up copy of your original before running the code on original file.
Sub DeleteEmptyColumns() 'Made It Easy By ExcelExciting.com Dim rng As Range Dim SelectRng As Range title = "ExcelExciting.com" Set SelectRng = Application.Selection Set SelectRng = Application.InputBox("Range :", title, SelectRng.Address, Type:=8) Application.ScreenUpdating = False For i = SelectRng.Columns.Count To 1 Step -1 Set rng = SelectRng.Cells(1, i).EntireColumn If Application.WorksheetFunction.CountA(rng) = 0 Then rng.Delete End If Next Application.ScreenUpdating = True End Sub
From the ribbion select Developer > Macros > Run