Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Report All Column Widths In Active Worksheet - an example

Hello,
No question here, just a procedure for the archive.

Search criteria: return column widths for all columns in active
worksheet get column widths get column width report column widths
examine list column width find all column widths all columns widths
Column's width columns' widths

Note: this procedure only works with Excel 2000 or higher as it uses
the Split function. Also this procedure rounds column widths to the
nearest whole integer. You may be able to get around this by editing
the procedure to use point widths and then do a conversion. I couldn't
find anything in the archive on how to do this, but then again, I
didn't look very hard either.

Sub ColumnWidthReport()

'Creates a new report worksheet that returns the column ID
'and each column's width. Only works with Excel 2000 or higher

Dim cell As Range
Dim ColumnWidthReportSheet As Worksheet
Dim TargetWorksheet As Worksheet
Dim ColWidth As Integer
Dim Row As Integer

On Error Resume Next

'Add a new worksheet
Application.ScreenUpdating = False
Set TargetWorksheet = ActiveWorkbook.ActiveSheet
Set ColumnWidthReportSheet = ActiveWorkbook.Worksheets.Add
ColumnWidthReportSheet.Name = "ColumnWidths in " &
TargetWorksheet.Name

ColWidth = 1

'Set up the column headings for Report worksheet
With ColumnWidthReportSheet
Range("A1") = "Column Number"
Range("B1") = "Column Letter"
Range("C1") = "Column Width"

Range("A1:C1").Font.Bold = True
End With

'Process each column
Row = 2
For Each col In TargetWorksheet.Columns
'Derive column width of the column
ColWidth = col.ColumnWidth

With ColumnWidthReportSheet
Cells(Row, 1).Value = col.Column
Cells(Row, 2).Value = Split(Columns(col.Column).Address,
"$")(2)
Cells(Row, 3).Value = ColWidth

Row = Row + 1

End With

Next

'Adjust column widths on Report sheet
ColumnWidthReportSheet.Columns("A:C").AutoFit
ColumnWidthReportSheet.Columns("A:C").HorizontalAl ignment =
xlCenter
Application.StatusBar = False

'Select a cell on the top of the report worksheet
Range("A2").Select

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Report All Column Widths In Active Worksheet - an example

Hi DataFreak,

Also this procedure rounds column widths to the
nearest whole integer. You may be able to get around this by editing
the procedure to use point widths and then do a conversion. I couldn't
find anything in the archive on how to do this, but then again, I
didn't look very hard either.


That is because you declared ColWidth As Integer!

Try changing the variable type.


---
Regards,
Norman


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Report All Column Widths In Active Worksheet - an example

With ColumnWidthReportSheet
Range("A1") = "Column Number"
Range("B1") = "Column Letter"
Range("C1") = "Column Width"

Range("A1:C1").Font.Bold = True
End With

Why use the With statement here since nothing references it?

--
Regards,
Tom Ogilvy

"DataFreakFromUtah" wrote in message
m...
Hello,
No question here, just a procedure for the archive.

Search criteria: return column widths for all columns in active
worksheet get column widths get column width report column widths
examine list column width find all column widths all columns widths
Column's width columns' widths

Note: this procedure only works with Excel 2000 or higher as it uses
the Split function. Also this procedure rounds column widths to the
nearest whole integer. You may be able to get around this by editing
the procedure to use point widths and then do a conversion. I couldn't
find anything in the archive on how to do this, but then again, I
didn't look very hard either.

Sub ColumnWidthReport()

'Creates a new report worksheet that returns the column ID
'and each column's width. Only works with Excel 2000 or higher

Dim cell As Range
Dim ColumnWidthReportSheet As Worksheet
Dim TargetWorksheet As Worksheet
Dim ColWidth As Integer
Dim Row As Integer

On Error Resume Next

'Add a new worksheet
Application.ScreenUpdating = False
Set TargetWorksheet = ActiveWorkbook.ActiveSheet
Set ColumnWidthReportSheet = ActiveWorkbook.Worksheets.Add
ColumnWidthReportSheet.Name = "ColumnWidths in " &
TargetWorksheet.Name

ColWidth = 1

'Set up the column headings for Report worksheet
With ColumnWidthReportSheet
Range("A1") = "Column Number"
Range("B1") = "Column Letter"
Range("C1") = "Column Width"

Range("A1:C1").Font.Bold = True
End With

'Process each column
Row = 2
For Each col In TargetWorksheet.Columns
'Derive column width of the column
ColWidth = col.ColumnWidth

With ColumnWidthReportSheet
Cells(Row, 1).Value = col.Column
Cells(Row, 2).Value = Split(Columns(col.Column).Address,
"$")(2)
Cells(Row, 3).Value = ColWidth

Row = Row + 1

End With

Next

'Adjust column widths on Report sheet
ColumnWidthReportSheet.Columns("A:C").AutoFit
ColumnWidthReportSheet.Columns("A:C").HorizontalAl ignment =
xlCenter
Application.StatusBar = False

'Select a cell on the top of the report worksheet
Range("A2").Select

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet Column Widths Different For Different Users Falcon Feet[_2_] Excel Discussion (Misc queries) 2 March 24th 10 01:05 PM
Different column widths within one worksheet saramac24 Excel Discussion (Misc queries) 4 February 8th 07 02:54 AM
Set different column widths on two halves of an Exc worksheet Ballooner Excel Discussion (Misc queries) 1 March 20th 06 08:07 PM
Are different column widths possible on the same worksheet? yinone Excel Worksheet Functions 6 November 18th 05 04:28 PM
Can I have different column widths in a worksheet? Kylie Excel Worksheet Functions 0 July 7th 05 05:03 PM


All times are GMT +1. The time now is 01:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"