Resize columns through VBA

MFish

Board Regular
Joined
May 9, 2019
Messages
76
Hi,

I am making a userform with checkboxes that will be a "Filter what you want to see" action. When you checkmark a checkbox it will then hide the designated column. When you uncheck it, it reverts back to unhide. My problem I have is it works great until you unhide the column and the column reverts to a default small width.

Code:
Code:
Sub checkbox1_click()
if checkbox1.value = true then
Columns("B").EntireColumn.Hidden = TrueelseColumns("B").EntireColumn.Hidden = Falseend sub

I'd like for the column to stay at a 15 width when you unhide it. How do I do that? And all of the checkboxes will be designated to a certain column and will all be the same width.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How about
Code:
Sub checkbox1_click()
If CheckBox1.Value = True Then
   Columns("B").EntireColumn.Hidden = True
Else
   Columns("B").EntireColumn.Hidden = False
   Columns("B").ColumnWidth = 15
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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