Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Getting Column width using macro..

I need some help creating a macro in MS Excel.

Say I have a worksheet with 20+ columns of various column
widths. All I need is to get the size of each column and
put it in a cell of the respective column.

If the cursor was placed on a row where the column
headings are available, I want the macro,

to get width of respective column and save it in the next
row
go to next column and do step 1
stop when no more columns are available (say it reaches
the empty cell)


After executing the macro, the Worksheet should look
something like this:

A B C D E
Name ID DOB Comment
15.14 8.43 11.14 25

Thanks in Advance for the help.
KM




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Getting Column width using macro..

I ran this code as a quick test on Column A


Columns("A:A").ColumnWidth = 15
Cells(1, 1).Select
ActiveCell = Selection.ColumnWidth


Hope that helps.

Steve
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Getting Column width using macro..

KM,

If Don's reply does not suit, this code will work out the last column and
add the column widths

Sub Widths()
Dim cLastCol As Long
Dim i As Long

cLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To cLastCol
Cells(2, i) = Columns(i).Width
Next

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"KM" wrote in message
...
I need some help creating a macro in MS Excel.

Say I have a worksheet with 20+ columns of various column
widths. All I need is to get the size of each column and
put it in a cell of the respective column.

If the cursor was placed on a row where the column
headings are available, I want the macro,

to get width of respective column and save it in the next
row
go to next column and do step 1
stop when no more columns are available (say it reaches
the empty cell)


After executing the macro, the Worksheet should look
something like this:

A B C D E
Name ID DOB Comment
15.14 8.43 11.14 25

Thanks in Advance for the help.
KM






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
Change Cell Width WITHOUT changing Column width dww701 Excel Discussion (Misc queries) 1 January 12th 09 10:52 PM
Macro for column width Martincito23 Excel Discussion (Misc queries) 4 January 10th 07 04:07 PM
how do I create multiple column width in the same column in excel Vish Excel Discussion (Misc queries) 9 November 3rd 06 11:49 PM
How to make cell width different than the column width it lies in John Excel Discussion (Misc queries) 2 September 11th 06 10:41 PM
Change the width of a single column in a column chart Dave Charts and Charting in Excel 2 December 13th 04 07:25 PM


All times are GMT +1. The time now is 04:43 PM.

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"