Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,560
Default sort macro, subtotal and add lines after subtotal

Hi All,

I want to develop a macro which can sort Asen my data based on column L,
subtotal based on column L, and total cloumn R and type total on column Q,
bold the total line and insert 4 lines and do the same for the rest of the
data.

the data range will change everytime i run the macro.

thanks

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default sort macro, subtotal and add lines after subtotal

Try this code

Sub MakeSubtotal()

LastRow = Range("L" & Rows.Count).End(xlUp).Row
Rows("1:" & LastRow).Sort _
header:=xlYes, _
key1:=Range("L1"), _
order1:=xlAscending

RowCount = 2
StartRow = RowCount
Do While Range("L" & RowCount) < ""
'see if data in column L doesn't match next row
If Range("L" & RowCount) < _
Range("L" & (RowCount + 1)) Then

'insert new row
Rows(RowCount + 1).Insert
'put total in new row in column Q
Range("Q" & (RowCount + 1)) = "Total"
'put formula in column R to get total
Range("R" & (RowCount + 1)).Formula = _
"=Sum(R" & StartRow & ":R" & RowCount & ")"
'make the row bold
Rows(RowCount + 1).Font.Bold = True

'add 4 more rows
Rows((RowCount + 2) & ":" & (RowCount + 4)).Insert
RowCount = RowCount + 5
StartRow = RowCount


Else
RowCount = RowCount + 1
End If
Loop

End Sub


"David" wrote:

Hi All,

I want to develop a macro which can sort Asen my data based on column L,
subtotal based on column L, and total cloumn R and type total on column Q,
bold the total line and insert 4 lines and do the same for the rest of the
data.

the data range will change everytime i run the macro.

thanks

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
macro excel subtotal in subtotal GBO Excel Discussion (Misc queries) 2 November 29th 07 02:15 PM
How do I Subtotal, then Sort by Subtotal Amounts? dnamertz Excel Discussion (Misc queries) 3 October 29th 06 12:17 AM
pasting to subtotal lines without replacing hidden -non-subtotal l harleydiva67 Excel Discussion (Misc queries) 1 October 12th 06 06:02 PM
Bolding the subtotal lines automaticlly When using the Subtotal fu 06Speed6 New Users to Excel 2 October 5th 06 03:52 PM
how can I print and sort JUST the subtotal lines, not the detail kamaladg Excel Discussion (Misc queries) 1 July 11th 06 12:34 AM


All times are GMT +1. The time now is 07:54 PM.

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"