autofit visible columns only

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Autofit on Visible Columns only

Autofit on Visible Columns only

resolvedResolved · Medium Priority · Version 2010

Matthew has attended:
Excel VBA Intro Intermediate course

Autofit on Visible Columns only

I have a spread sheet that is 200 lines down and approx. 78 columns wide. In some of the cells there are large amounts of "comment" type data that is used for reference.
I use "Custom Views" controlled by buttons and VBA to view the data sheet in about 6 different restricted views that allows me to present data to my audience and make changes live during a debate type meeting (hidden columns, full screen, formula bar of, different sorts on different columns etc). By restricting the views in this way we concentrate an particular aspects of the data.

My issue is that when I create a view that is only a few columns wide the row heights are still auto fitting to the data in the hidden columns and therefore rows look like a lot of blank space.

I've searched the internets various forums for ideas and come up with this vba being the best so far (see below) that allows me to size the cell on the visible data only but it steps through the entire spread sheet such that it take a minute or so to change to each view (little working circle on screen unable to do anything) before I can start working on it. When in a meeting this time feels like absolute ages with my audience sat patiently waiting (I can turn of the screen flicker with the screen updating command but you clearly still have to wait for it to complete the task).

The VBA was from a post on a forum made in 2003 so I was wondering if there is a more user friendly / quicker way I could achieve this task without the delay in excel 2010?

(My VBA is still very basic so most of this sub is quite foreign to me)

Sub sizeme()
Dim rngRow As Range
Dim rngAutofir As Range
Dim rngCopy As Range

Set rngAutofit = Range("b206")
For Each rngRow In Range("b6:b205").Rows
rngRow.EntireRow.SpecialCells(xlCellTypeVisible).Copy rngAutofit
rngAutofit.EntireRow.AutoFit
rngRow.RowHeight = rngAutofit.RowHeight
Next
rngAutofit.EntireRow.Clear

End Sub


Thanks.

RE: Autofit on Visible Columns only

Hi Matthew,

Thank you for the forum question.

I have as you searched forums without any better solution than the one you already have. I have also tested some of my own ideas without luck.

I am sorry I cannot find a better solution than the one which take time.

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Fri 28 Aug 2015: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Moving or Copying Sheets Between Workbooks in Excel 2010

Here's how to move or copy sheets between workbooks in Excel 2010:

Open the sheet you want to move or copy then on the Ribbon click the Home tab. Click Format. Under Organize Sheets, select the option Move or Copy Sheet and then choose where you want the sheet to be moved/copied to.

View all Excel hints and tips


Server loaded in 0.08 secs.