Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 36
Default Macro Help

I create lease payment schedules for different cities. The schedules have 9
columns across, but are varying in the number of rows down, anywhere from 30
to 3000+.

I would like to make a macro that would automatically sort by :

1. if the Payee (who the payment is to) has one line or more than one
(meaning if he is receiving 2 or more payments, move to the bottom), then
2. by the Payee Name, Alice Smith with 4 lines before John Smith with 2 lines
3. then by the payment number (alice smith has 4 payment numbers, john smith
has 2)

I can figure out the macro, but the problem is since the number of rows vary
by schedule and sometimes by month, (New York usually has about 3000, but one
month might be 2500, etc), I cant use the same macro because the cursor
always moves down a specific number of rows.

For Example: If I create the macro using a table of only 300 rows, but then
try to use it on a table of 3000, the macro will only format the first 300
rows.

Can anyone figure out how to make the cursor go to the bottom of the table
instead of the specific number of rows?

Below is the macro:

Sub FleetSort()
'
' FleetSort Macro
'

'
Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D5").Select
ActiveCell.FormulaR1C1 = "=OR(RC[-1]=R[-1]C[-1],RC[-1]=R[1]C[-1])"
Range("C6").Select
Selection.End(xlDown).Select
Range("D101").Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
Columns("D:D").ColumnWidth = 20.86
Columns("D:D").EntireColumn.AutoFit
Range("D8").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("D5:D101") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("C5:C101") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("H5:H101") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("G5:G101") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add
Key:=Range("B5:B101") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("B4:I101")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=-24
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
need help to update macro to office 2007 macro enabled workbook jatman Excel Discussion (Misc queries) 1 December 14th 07 01:57 PM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM


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