Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sum after sorting


I have 3 columns Column A Names, Column B Status and Column C Values.
In Column B i have 2 values Income and Outcome.
I've sorted this A and B Cells

Columns("A:C").Select
Selection.Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Key2:=Range("B2"), _
Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

I would like to add extra Rows and make Sum for each name create Incom
and Outcome Sums.
For example:
Column A # Column B # Column C #
##########################
Name # Status # Value #
##########################
David # Income # 10 #
##########################
David # Income # 30 #
##########################
David # Income Sum# 40 # <<- This Row Must Be added
##########################
David # Outcome # 50 #
##########################
David # Outcome # 20 #
##########################
David # Outcome Sum# 70 # <<- This Row Must Be added
##########################
Kate # Income # 30 #
##########################
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Sum after sorting

This should do the trick

:================================================= ========

Sub SummationLines()

Columns("A:C").Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Key2:=Range("B2"), _
Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

[B2].Select

Do Until IsEmpty(ActiveCell)
x = 0
qmark = ActiveCell.Value
Do Until ActiveCell < qmark
x = x + ActiveCell.Offset(0, 1).Value
ActiveCell.Offset(1, 0).Select
Loop
Selection.EntireRow.Insert
ActiveCell.Value = qmark & " Sum"
ActiveCell.Offset(0, 1) = x
ActiveCell.Offset(0, -1) = ActiveCell.Offset(-1, -1).Value
ActiveCell.Offset(1, 0).Select
Loop

End Sub

:================================================= ==

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sum after sorting


Thank you very much
Its working.
Is it possible to merge in column A
cells which comtain the same string

--
proto
-----------------------------------------------------------------------
proton's Profile: http://www.excelforum.com/member.php...fo&userid=3680
View this thread: http://www.excelforum.com/showthread.php?threadid=57334

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 Values Without Sorting Formulas SBX Excel Discussion (Misc queries) 2 April 12th 09 11:17 PM
Automatic sorting (giving max and min) based on custom sorting lis Joe Lewis[_2_] Excel Worksheet Functions 4 November 23rd 08 05:12 AM
Sorting VLookup vs Sorting SumProduct Lauren Excel Discussion (Misc queries) 1 August 21st 07 12:19 AM
Sorting: Sorting by the First Character dzuy Excel Discussion (Misc queries) 2 June 22nd 06 08:27 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


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