Multiple Column widths.

Darren Bartrup

Well-known Member
Joined
Mar 13, 2006
Messages
1,296
Office Version
  1. 365
Platform
  1. Windows
Morning all.

Hopefully a nice easy one to start the day off with.
Is there an easier way to write this:
Code:
            With rptWrkSht
                .Columns(1).ColumnWidth = 8.13
                .Columns(2).ColumnWidth = 18.25
                .Columns(3).ColumnWidth = 8
                .Columns(4).ColumnWidth = 12.63
                .Columns(5).ColumnWidth = 11.5
                .Columns(6).ColumnWidth = 12.38
                .Columns(7).ColumnWidth = 12.38
                .Columns(8).ColumnWidth = 9.75
                .Columns(9).ColumnWidth = 7.5
                .Columns(10).ColumnWidth = 13.13
                .Columns(11).ColumnWidth = 8.88
                .Columns(12).ColumnWidth = 10.63
                .Columns(13).ColumnWidth = 7.25
                .Columns(14).ColumnWidth = 18.38
            End With

I'm kinda hoping I can write something like:
Code:
rptWrkSht.Columns(1:14).ColumnWidth = array(8.13,18.25,8,.....)
But I can't find the right syntax :cry:

Please help before I go crazy!!
Ta.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
This one is not as nice as you want it to be but it works
Fill A1 to A12 with column width values
insert the follwing macro code:

For a = 1 To 12
Columns(a).ColumnWidth = Cells(a, 1)
Next a

and run it
have a good day

Ravi
 
Upvote 0
What you are suggesting could be done with an array:

Code:
Dim ColWdth As Variant, i As Integer

ColWdth = Array(8.13, 18.25, 8, 12.63, 11.5, 12.38, _
12.38, 9.75, 7.5, 13.13, 8.88, 10.63, 7.25, 18.38)

With rptWrkSht
    For i = 1 To 14
        .Columns(i).ColumnWidth = ColWdth(i - 1)
    Next i
End With
 
Upvote 0
Thanks for the help.
I haven't had time to try it out yet as I've been given another project which is 'more important than the last one' (as my boss puts it).
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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