LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default How to autofit variable columns?

"p45cal" wrote:
Untested, perhaps:

[....]
Range(sCell).Resize(nRow,nCol).EntireColumn.Autofi t


Tested. Perfetto! Grazie.

I don't know the "cost" of Resize, but FYI, the following works equally
well:

Range(sCell).Resize(1,nCol).EntireColumn.Autofit


----- original message -----

"p45cal" wrote in message
...

Joe User;618848 Wrote:
I have a macro that fills in one-line text in a variable range from
sCell to
Range(sCell).cells(nRow,nCol). When I am done, I want to autofit the
columns.

Originally, I wrote Range(sCell).Resize(nRow,nCol).Columns.Autofit.

Then I realized that this is autofitting based on only the new data.
Data
in pre-existing surrounding rows might require wider columns.

If sCell were "B6" and nCol were 10, and I did this manually, I would
select
columns B through K, and click on Format Column Autofit. Recording
a
macro, that effectively does Columns("B:K").Columns.Autofit.

How can I accomplish the same thing using the variables sCell, nRow
and
nCol?

I think either I want a variable Columns(...) specification that
encompasses
the columns from sCell through sCell+nCol-1, or I want a variable
Range(...)
or Resize(...) specification that encompasses the rows from 1 through
the
last-used row of the columns from sCell through sCell+nCol-1.

At least conceptually. I think.


Untested, perhaps:

Code:
--------------------
Range(sCell).Resize(nRow,nCol).EntireColumn.Autofi t
--------------------

?


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: 558
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=171976

Microsoft Office Help


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rows().AutoFit starts a calculation, but Columns().AutoFit doesn't Stefano[_2_] Excel Programming 1 November 30th 09 05:01 PM
Rows().AutoFit starts a calculation, but Columns().AutoFit doesn't Mike H Excel Programming 0 November 25th 09 04:31 PM
Autofit (Columns.EntireColumn.AutoFit) does not work Michiel via OfficeKB.com Excel Discussion (Misc queries) 3 February 10th 09 05:29 PM
Autofit Columns falcios Excel Discussion (Misc queries) 2 February 17th 07 04:08 PM
Columns.Autofit not doing what I want Ed Excel Programming 2 October 25th 04 11:31 PM


All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"