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:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,664
Members
449,045
Latest member
Marcus05

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
Back
Top