find columns width

RompStar

Well-known Member
Joined
Mar 25, 2005
Messages
1,200
I have a need to duplicate the column width from a workbook to a new workbook.

My column Range is A ~ AG. Is there some VBA code that I can employ that would scan this column range, find out their column widths ?

And then I could maybe play it back on a different sheet that is already setup to duplicate the columns exactly, just need to mimic the width, but the data is all different.

Thanks!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You could do something like this

Code:
ThisWorkbook.Sheets(1).Columns("A:G").Copy
ActiveWorkbook.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
 
Upvote 0
this is cool, but is there a way to capture the actual column width values ?

A - 12.25
B - 13.01
and so on...
 
Upvote 0
Try

Code:
Sub ColWidths()
Dim msg As String, i As Long
For i = 1 To 33
    msg = msg & i & vbTab & Columns(i).ColumnWidth & vbNewLine
Next i
MsgBox msg, vbInformation, "Column widths"
End Sub
 
Upvote 0
coool, I made small modification, because I wanted to capture the values to a sheet

I just run it on the sheet that had the widths that I needed and wrote their values to a different sheet, thanks!

Sub ColWidths()

Dim i As Long

For i = 1 To 33
Sheets("values").Range("A" & i).Value = i
Sheets("values").Range("B" & i).Value = Columns(i).ColumnWidth
Next i

MsgBox "Done"

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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