Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Sort worksheets by cell content

I'm not much of an Excel person, I'm more comfortable in SQL & VB.Net.

I have a workbook with sheets of various scores, and an overal score
averaged & summed into a single cell. I would like to arrange the worksheets
in descending order based upon the contents of cell G13.

I've looked at Pearson's sorting based on the sheet name but I don't know
how to extend it to sorting on a single cell. Any ideas?

Thanks for your time.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Sort worksheets by cell content

This doesn't do as much as Chip's code does, but maybe it'll be sufficient for
you--or at least get you started:

Option Explicit
Sub testme()
Dim myAddr As String
Dim wCtr As Long
Dim SwappedSheets As Boolean

myAddr = "A1"

Do
SwappedSheets = False
For wCtr = 2 To ActiveWorkbook.Worksheets.Count
If Worksheets(wCtr - 1).Range(myAddr).Value _
< Worksheets(wCtr).Range(myAddr).Value Then
Worksheets(wCtr).Move _
befo=Worksheets(wCtr - 1)
SwappedSheets = True
End If
Next wCtr
If SwappedSheets = False Then
Exit Do
End If
Loop

End Sub




R3dD0g wrote:

I'm not much of an Excel person, I'm more comfortable in SQL & VB.Net.

I have a workbook with sheets of various scores, and an overal score
averaged & summed into a single cell. I would like to arrange the worksheets
in descending order based upon the contents of cell G13.

I've looked at Pearson's sorting based on the sheet name but I don't know
how to extend it to sorting on a single cell. Any ideas?

Thanks for your time.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Sort worksheets by cell content

We are going to:

1. use a extra worksheet called helper
2. build a tiny table in the helper sheet with all sheetnames in column A
and the values of G13 (in that sheet) in column B
3. sort the table by column B
4. re-arrange the worksheets in the new order:

Sub sortum()
Sheets("helper").Activate
For i = 1 To Sheets.Count
Cells(i, 1).Value = Sheets(i).Name
Cells(i, 2).Value = Sheets(i).Range("G13").Value
Next

Columns("A:B").Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlNo

Sheets(Cells(1, 1).Value).Move befo=Sheets(1)
For i = 2 To Sheets.Count
Sheets(Sheets("helper").Cells(i, 1).Value).Move after:=Sheets(i - 1)
Next
End Sub
--
Gary''s Student - gsnu200805


"R3dD0g" wrote:

I'm not much of an Excel person, I'm more comfortable in SQL & VB.Net.

I have a workbook with sheets of various scores, and an overal score
averaged & summed into a single cell. I would like to arrange the worksheets
in descending order based upon the contents of cell G13.

I've looked at Pearson's sorting based on the sheet name but I don't know
how to extend it to sorting on a single cell. Any ideas?

Thanks for your time.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Sort worksheets by cell content

That worked.

Thank you.

"Gary''s Student" wrote:

We are going to:

1. use a extra worksheet called helper
2. build a tiny table in the helper sheet with all sheetnames in column A
and the values of G13 (in that sheet) in column B
3. sort the table by column B
4. re-arrange the worksheets in the new order:

Sub sortum()
Sheets("helper").Activate
For i = 1 To Sheets.Count
Cells(i, 1).Value = Sheets(i).Name
Cells(i, 2).Value = Sheets(i).Range("G13").Value
Next

Columns("A:B").Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlNo

Sheets(Cells(1, 1).Value).Move befo=Sheets(1)
For i = 2 To Sheets.Count
Sheets(Sheets("helper").Cells(i, 1).Value).Move after:=Sheets(i - 1)
Next
End Sub
--
Gary''s Student - gsnu200805


"R3dD0g" wrote:

I'm not much of an Excel person, I'm more comfortable in SQL & VB.Net.

I have a workbook with sheets of various scores, and an overal score
averaged & summed into a single cell. I would like to arrange the worksheets
in descending order based upon the contents of cell G13.

I've looked at Pearson's sorting based on the sheet name but I don't know
how to extend it to sorting on a single cell. Any ideas?

Thanks for your time.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Sort worksheets by cell content

This works, too.

Thank you.

It seems to me that this would be a common requrement for people who use
Excel a whole lot more than me, and Microsoft should include some builtin
functionality to accomplish it.

"Dave Peterson" wrote:

This doesn't do as much as Chip's code does, but maybe it'll be sufficient for
you--or at least get you started:

Option Explicit
Sub testme()
Dim myAddr As String
Dim wCtr As Long
Dim SwappedSheets As Boolean

myAddr = "A1"

Do
SwappedSheets = False
For wCtr = 2 To ActiveWorkbook.Worksheets.Count
If Worksheets(wCtr - 1).Range(myAddr).Value _
< Worksheets(wCtr).Range(myAddr).Value Then
Worksheets(wCtr).Move _
befo=Worksheets(wCtr - 1)
SwappedSheets = True
End If
Next wCtr
If SwappedSheets = False Then
Exit Do
End If
Loop

End Sub




R3dD0g wrote:

I'm not much of an Excel person, I'm more comfortable in SQL & VB.Net.

I have a workbook with sheets of various scores, and an overal score
averaged & summed into a single cell. I would like to arrange the worksheets
in descending order based upon the contents of cell G13.

I've looked at Pearson's sorting based on the sheet name but I don't know
how to extend it to sorting on a single cell. Any ideas?

Thanks for your time.


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Sort worksheets by cell content

I agree. Some people would also like to be able to group worksheets (like
folders).
--
Gary''s Student - gsnu200805


"R3dD0g" wrote:

This works, too.

Thank you.

It seems to me that this would be a common requrement for people who use
Excel a whole lot more than me, and Microsoft should include some builtin
functionality to accomplish it.

"Dave Peterson" wrote:

This doesn't do as much as Chip's code does, but maybe it'll be sufficient for
you--or at least get you started:

Option Explicit
Sub testme()
Dim myAddr As String
Dim wCtr As Long
Dim SwappedSheets As Boolean

myAddr = "A1"

Do
SwappedSheets = False
For wCtr = 2 To ActiveWorkbook.Worksheets.Count
If Worksheets(wCtr - 1).Range(myAddr).Value _
< Worksheets(wCtr).Range(myAddr).Value Then
Worksheets(wCtr).Move _
befo=Worksheets(wCtr - 1)
SwappedSheets = True
End If
Next wCtr
If SwappedSheets = False Then
Exit Do
End If
Loop

End Sub




R3dD0g wrote:

I'm not much of an Excel person, I'm more comfortable in SQL & VB.Net.

I have a workbook with sheets of various scores, and an overal score
averaged & summed into a single cell. I would like to arrange the worksheets
in descending order based upon the contents of cell G13.

I've looked at Pearson's sorting based on the sheet name but I don't know
how to extend it to sorting on a single cell. Any ideas?

Thanks for your time.


--

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
Sort column by amount of same content cells Mike M[_3_] Excel Discussion (Misc queries) 1 August 22nd 07 12:21 AM
Copy content of cell to another depending on value of third cell(between worksheets) Zeljko Milak Excel Worksheet Functions 2 July 14th 06 07:17 PM
Sort worksheets based on a cell value in each worksheet. Patrick Setting up and Configuration of Excel 4 May 3rd 06 01:52 AM
Copying worksheets into one workbook... based on content Petitboeuf Excel Discussion (Misc queries) 0 April 24th 06 01:21 PM
Sort columns by content Jane Excel Worksheet Functions 1 August 17th 05 06:25 PM


All times are GMT +1. The time now is 04:41 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"