开发者

How to detect if column contains value doesn't fitting it's width?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜