Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Autofit (Columns.EntireColumn.AutoFit) does not work

Anyone,

I have written a sub that does the following:
1) Add a new sheet to a workbook
2) Import a textfile into that worksheet
3) Performs an autofit to the columns with the imported data (Columns.
EntireColumn.AutoFit)

The last step does not seem to work. The line is executed but the column
width does not change.

If I run through it in debug mode and perform the Columns.EntireColumn.
AutoFit command in the Immediate window nothing happens either.

If I allow the code to finish (the "Columns.EntireColumn.AutoFit" was the
last command in that sub) and then appy the Columns.EntireColumn.AutoFit in
the Immediate window it works perfectly.

I checked the application.screenupdating parameter. It is TRUE. I also tried
adding a DoEventscommand after the Columns.EntireColumn.AutoFit but nothing
works.

What can be happening here? And how do I force Excel to compy to my commands?

M.

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default Autofit (Columns.EntireColumn.AutoFit) does not work

The code did not specify the columns to adjust, try something along the lines
of the following:

ActiveSheet.Columns("A:F").EntireColumn.AutoFit

--
Kevin Backmann


"Michiel via OfficeKB.com" wrote:

Anyone,

I have written a sub that does the following:
1) Add a new sheet to a workbook
2) Import a textfile into that worksheet
3) Performs an autofit to the columns with the imported data (Columns.
EntireColumn.AutoFit)

The last step does not seem to work. The line is executed but the column
width does not change.

If I run through it in debug mode and perform the Columns.EntireColumn.
AutoFit command in the Immediate window nothing happens either.

If I allow the code to finish (the "Columns.EntireColumn.AutoFit" was the
last command in that sub) and then appy the Columns.EntireColumn.AutoFit in
the Immediate window it works perfectly.

I checked the application.screenupdating parameter. It is TRUE. I also tried
adding a DoEventscommand after the Columns.EntireColumn.AutoFit but nothing
works.

What can be happening here? And how do I force Excel to compy to my commands?

M.

--
Message posted via http://www.officekb.com


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default Autofit (Columns.EntireColumn.AutoFit) does not work

You can use the following FOR loop to get all the columns if you're not sure
what columns need to be adjusted:

Sub AllColWid()

Dim i As Integer

Application.ScreenUpdating = False
For i = 1 To 256
ActiveSheet.Columns(i).EntireColumn.AutoFit
Next i
Application.ScreenUpdating = True


End Sub

--
Kevin Backmann


"Michiel via OfficeKB.com" wrote:

Anyone,

I have written a sub that does the following:
1) Add a new sheet to a workbook
2) Import a textfile into that worksheet
3) Performs an autofit to the columns with the imported data (Columns.
EntireColumn.AutoFit)

The last step does not seem to work. The line is executed but the column
width does not change.

If I run through it in debug mode and perform the Columns.EntireColumn.
AutoFit command in the Immediate window nothing happens either.

If I allow the code to finish (the "Columns.EntireColumn.AutoFit" was the
last command in that sub) and then appy the Columns.EntireColumn.AutoFit in
the Immediate window it works perfectly.

I checked the application.screenupdating parameter. It is TRUE. I also tried
adding a DoEventscommand after the Columns.EntireColumn.AutoFit but nothing
works.

What can be happening here? And how do I force Excel to compy to my commands?

M.

--
Message posted via http://www.officekb.com


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Autofit (Columns.EntireColumn.AutoFit) does not work

Hi Kevin,

Columns.EntireColumn.AutoFit command should work.

But you know, you still gave me the solution to the problem.
Apparently excel was noit able todetermine what Sheet I meant, despite the
fact that I selected it in the preceeding step.

Adding ActiveSheet (like you did) to the command solved the issue!

So, the correct line is:

ActiveSheet.Columns.EntireColumn.AutoFit

THANKS!!!!

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200902/1

Reply
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
Autofit and word wrap don't work? Jack Greb Excel Discussion (Misc queries) 12 January 15th 07 05:32 PM
Autofit doesn't work Rosemary Excel Discussion (Misc queries) 1 October 6th 06 04:21 AM
The Row Height Autofit command does not work. rstrefry Excel Worksheet Functions 4 July 19th 06 05:20 PM
Autofit doesn't work with merged cells Jen_G Excel Discussion (Misc queries) 3 January 30th 06 09:57 PM
Autofit Row height or Column Width does not work Gunjani Excel Discussion (Misc queries) 2 October 11th 05 09:19 PM


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

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

About Us

"It's about Microsoft Excel"