bepedicino
Board Regular
- Joined
- Sep 29, 2014
- Messages
- 73
I have the following VBA code that will delete columns that are entirely blank. I would like to modify the code so that if a range below the first three rows (headers) is blank, then the entire column will be deleted. Can anyone assist please?
Code:
Sub DeleteBlankColumns()'Step1: Declare your variables.
Dim MyRange As Range
Dim iCounter As Long
'Step 2: Define the target Range.
Set MyRange = ActiveSheet.UsedRange
'Step 3: Start reverse looping through the range.
For iCounter = MyRange.Columns.Count To 1 Step -1
'Step 4: If entire column is empty then delete it.
If Application.CountA(Columns(iCounter).EntireColumn) = 0 Then
Columns(iCounter).Delete
End If
'Step 5: Increment the counter down
Next iCounter
End Sub