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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel AutoFit Problem 1

Status
Not open for further replies.

baltman

Technical User
Mar 5, 2002
1,578
US
I'm issuing a ".Columns("B:K").EntireColumn.AutoFit" command... one of my rows is set to autowrap and bold. Sometimes that column is wrapping on a single word because the autofit is "1" too small. Is there a way to tell Excel to do something like:
".Columns("B:K").EntireColumn.AutoFit+1"

Or is there another workaround?

Thanks!
Brian
 
Brian,

Try this...

Sub Adjust_Width()
Columns("B:K").EntireColumn.AutoFit
cwidth = Columns("B:B").ColumnWidth
Columns("B:K").EntireColumn.Select
Selection.ColumnWidth = cwidth + 1
End Sub

Hope this helps. :) I tested it, and it seems to work, but feedback would be appreciated.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Thanks for the nudge in the right direction!

In the interest of full disclosure I am doing this inside a dynamic loop from FoxPro and creating anywhere between 1 and 250 sheets with anywhere between 1 and 250 columns (every sheet could have different columns) that would need this treatment.

My range is dynamic based on how many columns of data I'm populating... The problem is only with the column headers when the numbers under them are not as wide.

Here's what worked:

for counter=1 to numberofcols
varRange="'"+chr(68+counter)+":"+chr(68+counter)+"'"
cwidth = .Columns(&varRange).ColumnWidth
.Columns(&varRange).ColumnWidth = cwidth + 2
endfor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top