Change column width based on empty cells

vascobmcastro

New Member
Joined
Nov 19, 2015
Messages
5
Hi,

I have a table that ranges from columns G:AF. Row 3 (G3:AF3) has text which can be empty or not. How could I set a full column width for the columns that show empty values in the G3:AF3 range?

Thank you :)

Vasco
 
Try if this does what you want. You may have to adjust the widths as per your needs though.
Please save a back up of your file before trying my code as I am a VBA beginner.
Once you confirm that this serves the purpose, the expert member might give you a better and more efficient version of this.

VBA Code:
Sub adjustcolwidth()

Dim c As Range

    For Each c In Range("G2:AF2")

        If c = "" Then
            c.ColumnWidth = 0.5
           
            Else
            c.ColumnWidth = 3
        End If

    Next

End Sub
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,216,101
Messages
6,128,841
Members
449,471
Latest member
lachbee

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