Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Macro for column width

Hi,

I'm trying to make a macro which allows me to format a sheet. One of the
formats that I want to add in the macro is the column width. Below there is
part of the macro that I'm using in order to adjust the column width:

Columns("A:A").Select
Range("A3").Activate
Selection.ColumnWidth = 8
Columns("B:B").Select
Range("B3").Activate
Selection.ColumnWidth = 15
Columns("C:C").Select
Range("C2").Activate
Selection.ColumnWidth = 20
Columns("D:D").Select
Range("D2").Activate
Selection.ColumnWidth = 9
Columns("E:E").Select
Range("E3").Activate
Selection.ColumnWidth = 9
Columns("F:F").Select
Range("F3").Activate
Selection.ColumnWidth = 11
Columns("G:G").Select
Range("G2").Activate
Selection.ColumnWidth = 7
Columns("H:H").Select
Range("H4").Activate
Selection.ColumnWidth = 12
Columns("I:Q").Select
Selection.ColumnWidth = 5


The problem that I'm having is that from Columns A:H, the column width stays
at 12, and I:Q stays at 5. I'm actually expecting to have the columns A:H
with the width detailed in the macro. I know that there is something wrong in
the macro, but I can find what it is.

Can you please help me out??
Thank you!!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 142
Default Macro for column width

If you only want: Columns A:H,
at 12, and I:Q stays at 5, then


Columns("A:H").Select
Selection.ColumnWidth = 12
Columns("I:Q").Select
Selection.ColumnWidth = 5



"Martincito23" wrote:

Hi,

I'm trying to make a macro which allows me to format a sheet. One of the
formats that I want to add in the macro is the column width. Below there is
part of the macro that I'm using in order to adjust the column width:

Columns("A:A").Select
Range("A3").Activate
Selection.ColumnWidth = 8
Columns("B:B").Select
Range("B3").Activate
Selection.ColumnWidth = 15
Columns("C:C").Select
Range("C2").Activate
Selection.ColumnWidth = 20
Columns("D:D").Select
Range("D2").Activate
Selection.ColumnWidth = 9
Columns("E:E").Select
Range("E3").Activate
Selection.ColumnWidth = 9
Columns("F:F").Select
Range("F3").Activate
Selection.ColumnWidth = 11
Columns("G:G").Select
Range("G2").Activate
Selection.ColumnWidth = 7
Columns("H:H").Select
Range("H4").Activate
Selection.ColumnWidth = 12
Columns("I:Q").Select
Selection.ColumnWidth = 5


The problem that I'm having is that from Columns A:H, the column width stays
at 12, and I:Q stays at 5. I'm actually expecting to have the columns A:H
with the width detailed in the macro. I know that there is something wrong in
the macro, but I can find what it is.

Can you please help me out??
Thank you!!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro for column width

Your code worked ok for me.

Are you sure you're looking at the correct sheet.

And recording macros sometimes makes the code difficult to follow.

Your code is equivalent to:

Columns("A:A").ColumnWidth = 8
Columns("B:B").ColumnWidth = 15
Columns("C:C").ColumnWidth = 20
Columns("D:D").ColumnWidth = 9
Columns("E:E").ColumnWidth = 9
Columns("F:F").ColumnWidth = 11
Columns("G:G").ColumnWidth = 7
Columns("H:H").ColumnWidth = 12
Columns("I:Q").ColumnWidth = 5

Which is easier to read/modify.

======
Do you have merged cells in your data? Depending on the version of excel, maybe
that's the cause of the problem you're seeing.


Martincito23 wrote:

Hi,

I'm trying to make a macro which allows me to format a sheet. One of the
formats that I want to add in the macro is the column width. Below there is
part of the macro that I'm using in order to adjust the column width:

Columns("A:A").Select
Range("A3").Activate
Selection.ColumnWidth = 8
Columns("B:B").Select
Range("B3").Activate
Selection.ColumnWidth = 15
Columns("C:C").Select
Range("C2").Activate
Selection.ColumnWidth = 20
Columns("D:D").Select
Range("D2").Activate
Selection.ColumnWidth = 9
Columns("E:E").Select
Range("E3").Activate
Selection.ColumnWidth = 9
Columns("F:F").Select
Range("F3").Activate
Selection.ColumnWidth = 11
Columns("G:G").Select
Range("G2").Activate
Selection.ColumnWidth = 7
Columns("H:H").Select
Range("H4").Activate
Selection.ColumnWidth = 12
Columns("I:Q").Select
Selection.ColumnWidth = 5


The problem that I'm having is that from Columns A:H, the column width stays
at 12, and I:Q stays at 5. I'm actually expecting to have the columns A:H
with the width detailed in the macro. I know that there is something wrong in
the macro, but I can find what it is.

Can you please help me out??
Thank you!!


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 222
Default Macro for column width

You could leave out all the lines that start with Range but otherwise, it
works for me. Try stepping through the macro (F8) and observe what happens
on your spreadsheet.

"Martincito23" wrote:

Hi,

I'm trying to make a macro which allows me to format a sheet. One of the
formats that I want to add in the macro is the column width. Below there is
part of the macro that I'm using in order to adjust the column width:

Columns("A:A").Select
Range("A3").Activate
Selection.ColumnWidth = 8
Columns("B:B").Select
Range("B3").Activate
Selection.ColumnWidth = 15
Columns("C:C").Select
Range("C2").Activate
Selection.ColumnWidth = 20
Columns("D:D").Select
Range("D2").Activate
Selection.ColumnWidth = 9
Columns("E:E").Select
Range("E3").Activate
Selection.ColumnWidth = 9
Columns("F:F").Select
Range("F3").Activate
Selection.ColumnWidth = 11
Columns("G:G").Select
Range("G2").Activate
Selection.ColumnWidth = 7
Columns("H:H").Select
Range("H4").Activate
Selection.ColumnWidth = 12
Columns("I:Q").Select
Selection.ColumnWidth = 5


The problem that I'm having is that from Columns A:H, the column width stays
at 12, and I:Q stays at 5. I'm actually expecting to have the columns A:H
with the width detailed in the macro. I know that there is something wrong in
the macro, but I can find what it is.

Can you please help me out??
Thank you!!

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Macro for column width

Thanks to all of you I found the problem. The sheet had a few cells that were
merged, so instead of selecting each row separately, it was selecting A:H all
the time and changing its width several times.

Thank you all for your quick help!!!

"Dave Peterson" wrote:

Your code worked ok for me.

Are you sure you're looking at the correct sheet.

And recording macros sometimes makes the code difficult to follow.

Your code is equivalent to:

Columns("A:A").ColumnWidth = 8
Columns("B:B").ColumnWidth = 15
Columns("C:C").ColumnWidth = 20
Columns("D:D").ColumnWidth = 9
Columns("E:E").ColumnWidth = 9
Columns("F:F").ColumnWidth = 11
Columns("G:G").ColumnWidth = 7
Columns("H:H").ColumnWidth = 12
Columns("I:Q").ColumnWidth = 5

Which is easier to read/modify.

======
Do you have merged cells in your data? Depending on the version of excel, maybe
that's the cause of the problem you're seeing.


Martincito23 wrote:

Hi,

I'm trying to make a macro which allows me to format a sheet. One of the
formats that I want to add in the macro is the column width. Below there is
part of the macro that I'm using in order to adjust the column width:

Columns("A:A").Select
Range("A3").Activate
Selection.ColumnWidth = 8
Columns("B:B").Select
Range("B3").Activate
Selection.ColumnWidth = 15
Columns("C:C").Select
Range("C2").Activate
Selection.ColumnWidth = 20
Columns("D:D").Select
Range("D2").Activate
Selection.ColumnWidth = 9
Columns("E:E").Select
Range("E3").Activate
Selection.ColumnWidth = 9
Columns("F:F").Select
Range("F3").Activate
Selection.ColumnWidth = 11
Columns("G:G").Select
Range("G2").Activate
Selection.ColumnWidth = 7
Columns("H:H").Select
Range("H4").Activate
Selection.ColumnWidth = 12
Columns("I:Q").Select
Selection.ColumnWidth = 5


The problem that I'm having is that from Columns A:H, the column width stays
at 12, and I:Q stays at 5. I'm actually expecting to have the columns A:H
with the width detailed in the macro. I know that there is something wrong in
the macro, but I can find what it is.

Can you please help me out??
Thank you!!


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I email amacro? leo Excel Worksheet Functions 24 August 9th 06 02:47 PM
Macro question Chris Excel Worksheet Functions 12 July 7th 06 01:23 AM
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Editing a simple macro Connie Martin Excel Worksheet Functions 5 November 29th 05 09:19 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM


All times are GMT +1. The time now is 09:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"