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

autofit visible columns only

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

Autofit on Visible Columns only

ResolvedVersion 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:

How to apply the same formatting and data to multiple sheets at the same time in Excel 2010

When you want to format more than one sheet in a worksheet exactly the same way, Ctrl-click the tabs of the sheets you want to group together and they will all turn white. While they are grouped, anything you enter in one sheet gets entered into the others.

After you have done this, remember to click on the tabs to take them out of the group so that you do not accidentally insert data in multiple sheets when you just want to insert data in one.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.