how do i set column widths

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.
 
B

Bob Phillips

Take a look at the ColumnWidth property.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
G

Guest

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?
 
B

Bob Phillips

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)
 
D

Dave Peterson

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.)
 
G

Guest

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.)
 
M

Melody4572

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?
 
D

Dave Peterson

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top