Selecting Blank Columns

Carly

Active Member
Joined
Aug 21, 2002
Messages
370
I have a spreadsheet which consists of some columns having data and some not. The way it is formatting is:

Columns A & B are used then there is a blank column and then Columns D & E are used and there is a blank column & so on, upto column K.

What I would like to do is select all blank columns and set the columnwidth. Is there any way I can do this?

Regards

Carly
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I am a little new to this stuff but, you can create a macro that has the following lines:

Range("C:C,F:F,I:I,L:L,O:O").Select
Selection.ColumnWidth = 5

This is OK if you know the column names and its not liable to change else you must check to see if the column is empty I can give you the code for this if you need it
 
Upvote 0
Something like this?

Code:
Sub Test()
    Dim x As Integer
    With ActiveSheet
        For x = 1 To .Columns.Count
            If WorksheetFunction.CountA(.Columns(x)) = 0 Then
                .Columns(x).EntireColumn.ColumnWidth = 1
            End If
        Next x
    End With
End Sub
 
Upvote 0
Andrew,

This works just how I want it to apart from the fact, if possible, I would like it to stop when it gets to end of the data. So when it gets to column L there is no more data on the spreadsheet so instead of changing all the columns from L to IV, it would be better if it just stopped.

Is there a way this can be done?

Regards
Carly
 
Upvote 0
Well column L is 12, so:

Code:
Sub Test() 
    Dim x As Integer 
    With ActiveSheet 
        For x = 1 To 12 
            If WorksheetFunction.CountA(.Columns(x)) = 0 Then 
                .Columns(x).EntireColumn.ColumnWidth = 1 
            End If 
        Next x 
    End With 
End Sub
 
Upvote 0
Thanks that works great.

I didn't realise that those numbers represented the column numbers, but I understand now

Thanks again
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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