PDA

View Full Version : How to delete a Empty column?



smrobi
03-26-2011, 02:07 AM
Hello, I am trying to delete empty column of a excell sheet using macro. Can anyone help me by providing code.

Example: Please have the attachment, I want deleting entire Column "C" and "E". Please help.

mdmackillop
03-26-2011, 02:23 AM
Welcome to VBAX
This will check for blank columns and delete them for your posted sample.
Option Explicit

Sub DelCols()
Dim col As Long
Dim c As Range
Dim i As Long
'Find the last column in Row 1
col = Cells(1, Columns.Count).End(xlToLeft).Column
'Starting from the right
For i = col To 1 Step -1
'Is column empty?
If Cells(2, i).End(xlDown).Row = Rows.Count Then
'Delete column
Columns(i).Delete
End If
Next
End Sub

smrobi
03-26-2011, 07:17 AM
Thank you very much bro. It is working...