Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default sorting vertically.

I have a spreadsheet that I need to have the columns sorted by instead of
rows.

I have data like

Store Name ABC Store DEF Store GHI Store etc etc

Fruit Sales 100 150 200
Veg Sales 60 75 50

Total Sales 160 225 250



What I want to see is the top 10 stores by total sales so it would look like

GHI Store DEF Store ABC Store

Fruit Sales 200 150 100
Veg Sales 50 75 60

Total Sales 250 225 160

Can this be done?
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default sorting vertically.

One possibility: You could copy, edit/pastespecial/transpose the data to an
empty worksheet. Sort it by what is now the total column. Then
copy/pastespecial-transpose back to the original location. This can easily
be done manually.

I also included some code - but there are some assumptions made. It assumes
you select your data (excluding the far left column w/the descriptions - when
the data gets transposed these would become headers and the sort code assumes
no headers. You can change this, but the sort code has to also change to
recognize the header), then run the macro.

It also assumes the Total amount is the last row of data that you select.
When transposed, it is the last column which is used by the sort code.

Be sure to make backup copies!


Sub Sort()
Dim WkSht As Worksheet
Dim CopyRange As Range

Set CopyRange = Selection
Set WkSht = Worksheets.Add

CopyRange.Copy
WkSht.Range("A1").PasteSpecial Paste:=xlPasteAll, _
operation:=xlNone, skipblanks:=False, _
Transpose:=True
Application.CutCopyMode = False

With WkSht
'Sort by first row, last column - assumes no headers
.UsedRange.Sort Key1:=.Cells(1, .UsedRange.Columns.Count), _
Order1:=xlDescending, Header:=xlNo, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End With

WkSht.UsedRange.Copy
CopyRange(1, 1).PasteSpecial Paste:=xlPasteAll, _
operation:=xlNone, skipblanks:=False, _
Transpose:=True
Application.CutCopyMode = False
Application.DisplayAlerts = False
WkSht.Delete
Application.DisplayAlerts = True

End Sub


"ibbm" wrote:

I have a spreadsheet that I need to have the columns sorted by instead of
rows.

I have data like

Store Name ABC Store DEF Store GHI Store etc etc

Fruit Sales 100 150 200
Veg Sales 60 75 50

Total Sales 160 225 250



What I want to see is the top 10 stores by total sales so it would look like

GHI Store DEF Store ABC Store

Fruit Sales 200 150 100
Veg Sales 50 75 60

Total Sales 250 225 160

Can this be done?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default sorting vertically.

ibbm,
Manually, click the "Options" button at the bottom of the DataSort dialog.
select "Left to Right".
In code, the recorder generates something like this:
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight

NickHK

"ibbm" wrote in message
...
I have a spreadsheet that I need to have the columns sorted by instead of
rows.

I have data like

Store Name ABC Store DEF Store GHI Store etc etc

Fruit Sales 100 150 200
Veg Sales 60 75 50

Total Sales 160 225 250



What I want to see is the top 10 stores by total sales so it would look

like

GHI Store DEF Store ABC Store

Fruit Sales 200 150 100
Veg Sales 50 75 60

Total Sales 250 225 160

Can this be done?



  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default sorting vertically.

I never noticed there was an options button there.

"NickHK" wrote:

ibbm,
Manually, click the "Options" button at the bottom of the DataSort dialog.
select "Left to Right".
In code, the recorder generates something like this:
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight

NickHK

"ibbm" wrote in message
...
I have a spreadsheet that I need to have the columns sorted by instead of
rows.

I have data like

Store Name ABC Store DEF Store GHI Store etc etc

Fruit Sales 100 150 200
Veg Sales 60 75 50

Total Sales 160 225 250



What I want to see is the top 10 stores by total sales so it would look

like

GHI Store DEF Store ABC Store

Fruit Sales 200 150 100
Veg Sales 50 75 60

Total Sales 250 225 160

Can this be done?




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
Merge vertically ? bbelly Excel Discussion (Misc queries) 9 April 24th 23 09:06 PM
Vlookup Vertically Anto111 Excel Discussion (Misc queries) 4 November 6th 08 10:54 AM
How do I get my words to go vertically in Excel? Campbell New Users to Excel 4 May 30th 08 04:46 PM
How do I print vertically? (example A-T) Robin Excel Worksheet Functions 2 April 15th 05 04:52 PM
macro for merging vertically the second Excel Programming 7 May 9th 04 07:52 PM


All times are GMT +1. The time now is 05:10 PM.

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"