Delete empty Column with heading VBA

ojhawkins

New Member
Joined
Nov 17, 2011
Messages
39
Hi all again,

I am am wanting to delete the entire column if there are no entires below the heading in Row 1.

So in image below, Col C, E & G are to be delete including the heading.

Thanks again everyone

mwzn1x.png


Cheers,
O
 
Last edited:

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Dannyh1

Well-known Member
Joined
Nov 18, 2009
Messages
1,144
Hi,

Try:

Code:
Sub DELCOL()
Dim rng As Range
Dim lastrow As Long
Dim colnme As String
Dim cl
 
Set rng = Range("A1:G1")
 
For Each cl In rng
 
colnme = Left(cl.Address(0, 0), (cl.Column < 27) + 2)
 
lastrow = Cells(Rows.Count, colnme).End(xlUp).Row
 
    If lastrow = 1 Then
 
    cl.EntireColumn.Delete
 
    End If    
 
Next cl
 
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,463
Messages
5,596,283
Members
414,051
Latest member
tabecker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top