Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Modify Macro to Include Inserted Rows

Here is what I would do. This macro will sort rows that are below NAMES and
above TOTALS.

Option Explicit

Sub SortRows()

Dim rngNames As Range
Dim rngTotals As Range

' finds the cell with "NAMES"
Set rngNames = Sheets("Sheet1").Columns("A:A").Find(What:="NAMES" , _
After:=Cells(1, 1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

' finds the cell with "TOTALS"
Set rngTotals = Sheets("Sheet1").Columns("A:A").Find(What:="TOTALS ", _
After:=Cells(1, 1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)


ActiveSheet.Rows(rngNames.Row + 1 & ":" & rngTotals.Row - 1).Sort
Key1:=Range("A2"), _

Order1:=xlAscending, _

Header:=xlGuess, _

OrderCustom:=1, _

MatchCase:=False, _

Orientation:=xlTopToBottom

End Sub

Hope this helps. If so please click yes below.
--
Cheers,
Ryan


"Icefog" wrote:

That almost does what I want it to. The macro provided assumes that
the sort will always being in at A2 (right?). How do I get the macro
to point to headings and words in the cells. For example:

NAME TEST 1 TEST 2
blank 2 7
Man 2 6
zebra 3 9

TOTALS 7 22

NAME TEST 1 TEST 2
able 3 5
cain 4 6
sport 2 7

TOTALS 9 18

I want to insert / delete rows between NAME and TOTALS and the macro
will expand to sort the names accordingly. And it would need to
happen multiple times on the same worksheet as evidenced above.

Chris.....

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
modify macro to include more tabs teh_chucksta Excel Discussion (Misc queries) 1 March 11th 10 09:00 PM
Macro to Number New Rows Inserted Into Table? Lysander Stark Excel Discussion (Misc queries) 2 August 28th 06 04:49 PM
Can inserted rows automatically include existing worksheet formula tgdavis Excel Discussion (Misc queries) 2 September 20th 05 09:08 PM
Modify A Formula To Include AND carl Excel Worksheet Functions 2 August 21st 05 03:41 PM


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