how do i set column widths

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to set the column widths to various sizes. I have columns A thru P
with headers and I want to make a macro that sets the column width of each
column to a certain size. For example column A 5.29 or 42 pixels, column B
16.00 or 117 pixels, etc.
 
Take a look at the ColumnWidth property.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
I looked it up in help and it did not help me. How do I write a macro that
will set the column widths as I described?
 
Help says it as far as I can see

columns(1).columnwidth = 8.43

as an example

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
I got this when I recorded a macro:

Option Explicit
Sub Macro1()
Columns("G:G").ColumnWidth = 11.29
Columns("D:D").ColumnWidth = 10.86
End Sub

Maybe you can use it. (I'd try recording a macro once more. I'm guessing that
you did something wrong the first time.)
 
Thanks! I made it work using what you copied.

Dave Peterson said:
I got this when I recorded a macro:

Option Explicit
Sub Macro1()
Columns("G:G").ColumnWidth = 11.29
Columns("D:D").ColumnWidth = 10.86
End Sub

Maybe you can use it. (I'd try recording a macro once more. I'm guessing that
you did something wrong the first time.)
 
Pardon me for 'piggybacking' on your thread lpdarspe; but how do I make it
stay once it formatted? Protecting the sheet isn't working as they remove
it. Can I just tell it Sub stance()
Range("A:A").ColumnWidth = 2
Range("B:B").ColumnWidth = 7
End Sub

and so forth, will it automatically open and stay at this size? or is there
something else I need to do to make this happen?
 
Those columnwidths should stay that way until you (or the user) does something
to change them.

If you really want to stop anyone from changing the width, you could protect the
sheet (tools|Protection|protect sheet (in xl2003)).

But there are lots of things that won't work when you protect the sheet.

Pardon me for 'piggybacking' on your thread lpdarspe; but how do I make it
stay once it formatted? Protecting the sheet isn't working as they remove
it. Can I just tell it Sub stance()
Range("A:A").ColumnWidth = 2
Range("B:B").ColumnWidth = 7
End Sub

and so forth, will it automatically open and stay at this size? or is there
something else I need to do to make this happen?
 
Back
Top