Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting with a macro?

I want to automate a sorting process for a spreadsheet that I have. On
this sheet, I have various groups of names that I want to sort
alphabetically within each group. For example, cells A1:A10 should be
sorte a-z, cells A11:A20 sorted a-z, etc.

I will be updating this list from time to time with more names, and
I'll need to resort it each time. There are 10 groups of names that I
want sorted, and it's very tedious to select 10 different sets of cells
and then tell it how to sort 10 different times.

I've created a macro to do this, which works great. My problem is that
if I allow 15 cells for each set of names (so, 15 names) and 6 months
from now I need to add two rows because I have 17 names in a particular
category, the macro I've created won't sort properly, because it's only
expecting a range of 15 cells.

Is there a way to make a sort function that will take into account a
change in the number of cells in a group?

(I hope you can understand this from my description)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Sorting with a macro?

Without seeing your code, it's difficult to say, but ...........

Watch for line wrap. Use the intI value for the number in the sort.

Dim intI As Integer

intI = Application.InputBox(Prompt:="Enter the number of rows to
sort.", Type:=1, Default:=10)

If intI = 0 Then Exit Sub

HTH
Paul
-----------------------------

On Fri, 29 Aug 2003 16:20:48 -0400, gschimek
wrote:

I want to automate a sorting process for a spreadsheet that I have. On
this sheet, I have various groups of names that I want to sort
alphabetically within each group. For example, cells A1:A10 should be
sorte a-z, cells A11:A20 sorted a-z, etc.

I will be updating this list from time to time with more names, and
I'll need to resort it each time. There are 10 groups of names that I
want sorted, and it's very tedious to select 10 different sets of cells
and then tell it how to sort 10 different times.

I've created a macro to do this, which works great. My problem is that
if I allow 15 cells for each set of names (so, 15 names) and 6 months
from now I need to add two rows because I have 17 names in a particular
category, the macro I've created won't sort properly, because it's only
expecting a range of 15 cells.

Is there a way to make a sort function that will take into account a
change in the number of cells in a group?

(I hope you can understand this from my description)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Sorting with a macro?

I assume that all 10 groups are assigned the same number of rows, right? i.e. if you add 2 items
to the 2nd group, you will also add 2 to every one of the groups. If that's correct, you could
put the number of rows in a group in a worksheet cell, or define it as a constant or variable at
the top of your module. Modify the code to read this value and define the group size
accordingly. i.e.

Dim i As Long
Dim NumRows As Long
Dim Rng As Range

NumRows = Worksheets("Sheet1").Range("K1").Value
Set Rng = Range("A1").Resize(NumRows)
For i = 1 to 10
Rng.Sort .....
Set Rng = Rng.Offset(NumRows, 0)
Next i


On Fri, 29 Aug 2003 16:20:48 -0400, gschimek wrote:

I want to automate a sorting process for a spreadsheet that I have. On
this sheet, I have various groups of names that I want to sort
alphabetically within each group. For example, cells A1:A10 should be
sorte a-z, cells A11:A20 sorted a-z, etc.

I will be updating this list from time to time with more names, and
I'll need to resort it each time. There are 10 groups of names that I
want sorted, and it's very tedious to select 10 different sets of cells
and then tell it how to sort 10 different times.

I've created a macro to do this, which works great. My problem is that
if I allow 15 cells for each set of names (so, 15 names) and 6 months
from now I need to add two rows because I have 17 names in a particular
category, the macro I've created won't sort properly, because it's only
expecting a range of 15 cells.

Is there a way to make a sort function that will take into account a
change in the number of cells in a group?

(I hope you can understand this from my description)


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
Sorting Macro Jamie Excel Worksheet Functions 4 September 18th 09 06:53 PM
Help with Macro for sorting Brad[_6_] Excel Worksheet Functions 2 August 10th 09 04:20 PM
macro for sorting cherrynich Excel Discussion (Misc queries) 1 December 30th 04 04:47 PM
Sorting w/Macro Joe[_24_] Excel Programming 1 August 28th 03 07:44 PM
sorting macro Beth Mc[_2_] Excel Programming 2 August 1st 03 03:49 AM


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