Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofit columns in multiple worksheets

Status
Not open for further replies.

munchen

Technical User
Aug 24, 2004
306
GB
I have an excel workbook that has multiple worksheets. When I open the workbook I always want a range to be cleared for example:

Range("A6:E300").Select
Selection.Clear

Also once I click on Refresh All to refresh each worksheet (each worksheet runs a query) I want each column in each worksheet to autofit.

Is there a simple way to do this in VBA?
 
1) use the Workbook_Open event procedure
2) use the AdjustColumnWidth property of each of your QueryTable (NO VBA needed)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Thanks for your reply. Bear with me I'm new to VBA.

As I mentioned I've got multiple worksheets.

In the 1st sheet (the sheet that is displayed when opened in excel) should I use the workbook_open_event procedure?

Private Sub Workbook_Open()

Sheets.Select
Columns("A:J").EntireColumn.AutoFit

End Sub

What do you mean by using the AdjustColumnWidthProperty for each Query? Do you mean I have to amend the adjustcolumnwidth property on each sheet (there are quite a lot)?
 



In the QueryTable for each worksheet, the Data Range Properties has a checkbox for Auto adjusting columns.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top