Autofit non contiguous columns containing merged cells across columns

F

Fred

Can someone help me out here please. I can manually select columns H,
K, L, M, Q thru V, X and Y and excel neatly selects the individual
columns, I can then Format, Column, Autofit Selection and it ignores
the fact that there are merged cells spreading across the sheet.
However when I try the same in VB it selects across the whole sheet
because there are merged cells across various of the columns and
spreads out across and beyond the width of the screen.

I tried performing the task manually and recording my actions into a
macro, it generated the following code, but when I ran the code in my
overall macro it simply grabs columns B thru X because that is where
there is a set of merged cells, and expands the width "ignoring my
wishes".

Range("H:H,K:K,L:L,M:M,Q:V,X:Y").Select
Range("X29").Activate
Selection.Columns.AutoFit

Is there a way around this "feature"

Thanks in advance

Regards
Fred
 
D

Dave Peterson

Each version of excel seems to treat merged cells differently. In xl97, even
manually selecting a single column that was merged with adjacent columns
selected those multiple columns (IIRC).

But VBA seems not to have changed with respect to this.

In my mind, it's another reason to avoid merged cells.

Nope. I don't know of a workaround.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top