How to make Excel report width of columns(s)?

L

Legacy 32120

Guest
Hi,

I'm looking for a macro or function/formula to list & total a range of column widths. Having lots of columns with varying widths t'would rather not have to do it manually from each column's Properties.

Thanks....

Max :)
 
Code:
Option Explicit

Sub CellWidth()
    Dim c As Range
    For Each c In Range("A1:Z1")   '<<< change to your range of columns
        '
        'use one (and only one) of the folowing statements
        c = c.ColumnWidth           'actual columns width including decimals
        c = Round(c.ColumnWidth, 0)    'column width rounded to integer
        c = Int(c.ColumnWidth)     'integer portion of column widthe
    Next c
End Sub
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Thanks Bill,

That works nicely :)

A minor point, the figure in column C comes out underlined & in blue like a hyperlink.

Now, what to add to autocalculate the total width(s)?

Cheers,

Max
 
Upvote 0
Hi again tnazirov,

Got what you mean thanks. No, not integer but decimal figures.

Cheerio,

Max :)
 
Upvote 0
Hi again tnazirov,

Got what you mean thanks. No, not integer but decimal figures.

Cheerio,

Max :)


Hi Makka,
By definition of function we receive integers. I, for example, receive integers.
But if you receive decimal numbers is even better.
Good luck.
 
Upvote 0
To get total column width of range entered
Code:
Option Explicit

Sub CellWidth()
    Dim c As Range
    Dim TotalColWidth As Double
    For Each c In Range("A1:Z1")   '<<< change to your range of columns
        '
        c = c.ColumnWidth           'actual columns width including deimals
        TotalColWidth = TotalColWidth + c
    Next c
    Range("A2") = TotalColWidth
End Sub

A minor point, the figure in column C comes out underlined & in blue like a hyperlink.

Must be a formating problem. Clear All (not Clear Contents) the cell in question and try again.
 
Upvote 0
Great Bill!

First go made a few figures come out in bold.
Used 'Clear All' as you said and that fixed that.

Much obliged to you mate!

All the best...

Max :)

P.S. Care to have a go with my post - 'Create index of sheet data'?
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,617
Members
449,039
Latest member
Mbone Mathonsi

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