Macro to set column widths in a worksheet

P

Phil Bracken

Hi,
I've tried to create a macro that will go in and set the column widths
(columns A thru M) to specific widths. Each column is a different
width. I used the record button and set them as I wanted and then
stopped the recording. When I went to another worksheet in the same
workbook and executed I could see it change the width for a split
second and then they each went to a standard 7.71 width. No error
messages. No explanations.

My goal is a macro to be able to import or copy a page from 5
different worksheets that I receive twice a month and be able to view,
print and extract data from them for other reports.

Thanks in advance,
Phil
 
J

JLGWhiz

Without seeing the code, it is impossible to determine what happened.
However, column width is a function of format and many things affect the
format of cells, columns and rows such as copying from one sheet to another
or from one workbook to another. If you are running SQL, it could have code
that affects format, although rarely so. Your sheet could have had an event
code in it that reset the column width. As I said, there are many things
that could happen after the column width and/or row height is set that might
cause them to change to default or other preset sizes. If you want the best
assistance, post the relevant code so everone can see it.
 
J

JLGWhiz

P.S. You might consider running your column width macro after you have
imported data from other workbooks. That would prevent the import process
from changing the format.
 
P

Phil Bracken

I've checked and must have deleted the file I was trying to work from.
it was a workbook that had been previously set up by someone else. It
was designed to be printed and then filled in by personnel monitoring
some helium purification equipment. There were merged cells but no
formulas or data entered on it yet.

This was basically practice so that I could perhaps set up a macro to
go in and set column widths in worksheets that I receive twice a month
from our blimp operations. The guys in the field have "tweaked" their
worksheets for their printers, added client logos at the top of the
form and other minor changes. What I want to be able to do is collect
these worksheets in a folder or a master workbook and then be able to
pull data from each one into a summary.

I realize I can pull data from worksheets without worrying about the
column widths but when they are printed and you thumb through them, it
looks terrible. I guess I was just going to tidy it up a bit.

I created a new workbook, increased the number of worksheets for what
I needed and recreated the macro. it worked flawlessly! Which now
brings to mind, how can I be sure that a macro will run on worksheets
from 5 different operators? They were originally all created from one
master workbook but over the years have been passed from one mechanic
to another. They have not been altered radiucally, at least to the
eye, but if that relatively simple macro wouoldn't run on a "empty"
worksheet, what will it do with one that has data in the cells?

Thanks again!

Phil
 

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