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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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