Deleting Blank Columns

sdohertyccb

Board Regular
Joined
Feb 15, 2005
Messages
91
Can anyone give me a clue as to what I need to do to search for blank columns in a range and delete them? I can do this for blank rows, but am stuck on deleting blank columns.
Here is the code I have started for the blank rows, but am lost on the columns section.

Code:
 For a = 1 To lastrow Step 1
            If IsEmpty(Range("B" & a)) Then
            Range(a & ":" & a).Select
            Selection.Delete Shift:=xlUp
            End If
        Next a
        For b = 1 To lastcol Step 1
            If IsEmpty(range() Then
            Columns(b).Select
            Selection.Delete
            End If
        Next b
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try

Code:
For b = lastcol To 1 Step -1
    If WorksheetFunction.CountA(Columns(b)) = 0 Then Columns(b).Delete
Next b

the row deleting part should also loop backwards.
 
Upvote 0
Peter,
That worked like a charm...
I know there had to be an easy solution to this.
I truly appreciate your help!
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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