Setting column width, too wide

bkelly

Active Member
Joined
Jan 28, 2005
Messages
465
I am copying the format of one worksheet to another and setting the column widths the same. This line
Code:
column_width = original_ws.Cells(width_row, column).Width
returns 82
The cell is about an inch wide. This line sets the column about five inches wide
Code:
new_ws.Columns(column).ColumnWidth = column_width
I am guessing that points are getting confused with pixels.
Complicating factor: The first row has the first cell merged out to column J. I added code to check for merge = true and when true, call a function that steps down in rows until the cell is no longer merged. That function still returns width of 82. It is here:
Code:
Function Find_First_Not_Merged_Row(this_sheet As Worksheet, last_row As Long, column As Long) As Long
Dim test_range As Range
Dim row As Long
With this_sheet
   For row = 1 To last_row
       Set test_range = .Range(.Cells(row, column), .Cells(row, column))
       If (test_range.MergeCells = False) Then
           Exit For
       End If
   Next row
   Find_First_Not_Merged_Row = row
End With
End Function

(Yes, the above for loop should be 2 to last_row but I set it to 1 just to see that the If would not exit on the first row. It did not.)
What am I missing?
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
The (read-only) Width property return points (1/72 inch), while the (read/write) ColumnWidth property is in characters.

If you want two columns to be the same width,

Code:
new_ws.Columns(column).ColumnWidth = original_ws.Cells(width_row, column).ColumnWidth

... assuming both are in the same workbook.

You can also copy and pastespecial column widths.
 
Last edited:
Upvote 0
As you noted I was not using .ColumnWidth consistently. That is working now.
Thank you for taking the time to post.
 
Upvote 0

Forum statistics

Threads
1,221,446
Messages
6,159,917
Members
451,603
Latest member
SWahl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top