Question : How can I display the current column widths of an Excel worksheet?

In Excel 2003, I would like to be able to select a single worksheet, and then run a macro that would create a new worksheet and display in row 1 the column widths of the selected worksheet.

Answer : How can I display the current column widths of an Excel worksheet?

If you want to match the values reported by the Format...Cells...Column Width menu item, then the following macro will do so. It asks the user to select a range of cells that includes the desired columns. It will then add a worksheet at the end of the workbook to display the columns widths.

Brad
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Sub ColumnWidths()
Dim targ As Range, cel As Range
On Error Resume Next
Set targ = Application.InputBox("Please select the range you want to report columns widths for", Type:=8)
On Error GoTo 0
If targ Is Nothing Then Exit Sub

Application.ScreenUpdating = False
Set targ = targ.Rows(1)
With Worksheets.Add(after:=Worksheets(Worksheets.Count))
    For Each cel In targ.Cells
        .Cells(1, cel.Column) = cel.EntireColumn.ColumnWidth
    Next
End With
Application.ScreenUpdating = True
End Sub
Random Solutions  
 
programming4us programming4us