LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Sorting columns - can't maintain column width

I have a worksheet that contains 268 columns with headers. I have a couple
of different ways I want to sort the data left to right by columns. The sort
itself works fine -- the issue is that I can't seem to maintain the integrity
of the original column width for each column of data. For example, let's say
the 'original' column width is as follows:

A = 10 B = 15 C = 5

If I sort the data so that columns B & C become reversed, the data that
'was' in column C now has a width of 15 (too large), while the data from
column B now has a width of 5 (too small). I cannot use autofit afterwards
because the wrapped headers in each column cause the widths to become even
more distorted. I am using VB code to perform the sort function--here is an
example of one of the sorts. Is there something I can do to maintain the
integrity of the column width so it stays with the original data?

Sub Sort_by_Measure()
'Sort columns left to right by Measure, then by Quarter
Application.ScreenUpdating = False
UnhideCols
Columns("E:JZ").Select
ActiveWorkbook.Worksheets("Detail").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Detail").Sort.SortField s.add
Key:=Range("E6:JZ6") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Detail").Sort.SortField s.add
Key:=Range("E5:JZ5") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Detail").Sort
.SetRange Range("E1:JZ20000")
.Header = xlNo
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Hide_Detail_Cols
Range("A11").Select
Application.ScreenUpdating = True
End Sub

 
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
Increasing width of columns in column chart Shelly Charts and Charting in Excel 2 June 22nd 09 02:36 AM
How to alter width of columns in Column Charts? TimJim Charts and Charting in Excel 2 January 16th 07 01:00 AM
How can I set width of the columns in the column graph? yulia Charts and Charting in Excel 1 December 16th 06 09:04 PM
Set Column Width Based On Total Width Of Other Columns rayneraingoaway Excel Programming 1 June 28th 06 11:10 PM


All times are GMT +1. The time now is 06:36 AM.

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

About Us

"It's about Microsoft Excel"