Hidden Columns Still Have a Width > 0

brand_nubian

New Member
Joined
Apr 27, 2015
Messages
4
Hi,

I am new and I have searched for a solution to this problem for a few hours. I couldn't find any questions that directly addressed my issue, so here it goes:

I am working on a macro that involves many steps of formatting for one worksheet. Much of that work involves hiding rows and columns. One part of the code, below, works for the most part, in that it attempts to hide the columns I want to hide. The problem is there are many hidden columns (~20 or so) and they aren't completely hidden, just mostly hidden. After my program runs, many of the hidden columns still have a width of 0.58. This leaves the resulting document unbalanced because most of the partially-hidden columns are in one space that I want to have set to a specific width. I have tried adding a line of code to adjust the selected column's width to 0, as you can see below, but that has not resolved the problem. This is just speculation, but one cause I can think of is that in multiple places, I have merged cells across the columns that I intend to hide. What could cause this to happen?

Thanks!

Code:
Dim c as Range

For each c in Range("Column_Helpers")

If cell.Value = "HIDE" Then

    cell.EntireColumn.Hidden = True
    cell.EntireColumn.ColumnWidth = 0

End If
Next
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I wonder if the problem is not caused by asking excel to go and look for c in a hidden column after next. Wwhat is the range of the colum helpers? Could you post more of the code?

Otherwise would this change anything?

Code:
Dim c as Range

For each c in Range("Column_Helpers")

If cell.Value = "HIDE" Then
    cell.select
    selection.EntireColumn.Hidden = True

End If
Next
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

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