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!

Selective AutoFit

Status
Not open for further replies.

tweek312

Technical User
Dec 18, 2004
148
US
I have this code which I use for selecting key sheets in a workbook and have adapted many functions off of it but for some reason I cannot get this one specific (simple) function to work.

I need to autoFit the entire contents of each selected sheet. Currently I am using the below code. It works fine for the first selected sheet in the array but when I go to check the second and third sheets the data is not autoFit. I have tried a lot of stuff, but the fact is that I dont know enough to troubleshoot this one. Pleaase Hellllp!... Its probably somthing stupid like a missing comma or declaration.

Argh..!

Thx - Tw33k

Code:
Sub autoFit()
s = ""
For Each ws In Worksheets
    If ws.Name Like "!*" Then s = s & Chr(1) & ws.Name
Next ws
Sheets(Split(Mid(s, 2), Chr(1))).Select

Sheets("!Crest National").Activate
    Cells.Select
    Selection.Columns.autoFit

End Sub
 
Why not simply this ?
For Each ws In Worksheets
If ws.Name Like "!*" Then ws.Columns.AutoFit
Next ws

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Doesn't seem to work... what exactly are you suggesting?

Tx - Tweek
 
Help about what ?
What's wrong with the code I suggested you ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Nevermind the code works fine... Im just an idiot. :(

Thanks PHV! =D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top