I need to detect if column has some values which need more wi开发者_如何学JAVAdth (that ones shown as ###### in the grid)
The solution depends on how the data is entered into the cells.. the below might get you started:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Cells.Columns.AutoFit
End Sub
Or to affect one sheet - e.g. in a macro - you could change it to pass through the sheet number/name
Sub SetColWidth()
Sheets(1).Columns.AutoFit
End Sub
or to go through ALL the sheets and set them all at once:
Sub SetColWidthAllSheets()
Dim s As Worksheet
Application.ScreenUpdating = False
For Each s In Sheets
s.Columns.AutoFit
Next
Application.ScreenUpdating = True
End Sub
Hope this helps
EDIT: Added ScreenUpdating to above code.
精彩评论