This one is fun, so I wrote it out. Essentially this script will treat your wsFROM as if it were a database table, then it will apply the SQL statement to it to do what you need and return the results to wsTO. It should run pretty quickly even though it's 20000 records. The alternative would be to loop through every row in the sheet and then look to see if there's others like it and add the results. It would be one of those 20 minute running nightmare VBA routines, where this should run in a few dozen seconds.
Make sure you change the SET wsFROM... and Set wsTO... lines to be your worksheets. Other than that, I believe it shouldT work with your data as is.
Sub excelSQL()
'Variables
Dim objConn As Object
Dim rs As Object
Dim strFileName As String, strSQL As String, strConn As String
Dim wsFrom As Worksheet, wsTo As Worksheet
'set the worksheet with the data and the worksheet to dump the results
Set wsFrom = Worksheets("Sheet1")
Set wsTo = Worksheets("Sheet2")
'Make a new file with _tmp appended to it in same folder
strFileName = ThisWorkbook.Path & "/" & ThisWorkbook.Name
strFileName = Replace(strFileName, ".xls", "_tmp.xls")
ThisWorkbook.SaveCopyAs strFileName
'Fancy ADODB stuff.. essentially open up that copy we just saves as if it were a database
Set objConn = CreateObject("ADODB.Connection")
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFileName & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
objConn.Open strConn
'This is the sql string we will use to query the excel/database. The field names are the names in Row 1 of the sheet
strSQL = "SELECT [Number],[NAME],[Up/Down],[FYE],[GL_ACCT_GRP],[GL_SEG_CD],[ACCT#],[CODE],[REGION],Sum(Amount1), Sum(Amount2) FROM [" & wsFrom.Name & "$] GROUP BY [Number],[NAME],[Up/Down],[FYE],[GL_ACCT_GRP],[GL_SEG_CD],[ACCT#],[CODE],[REGION];"
'Fancy ADODB stuff to apply that SQL statement to the excel/database
Set rs = CreateObject("ADODB.Recordset")
rs.Open strSQL, objConn
'get headers
Dim header as object
Dim headerCol as integer
headerCol = 1
'Loop through fields in the recordset
For each header in rs.fields
'Stick them in Row 1
Cells(1, headerCol).value = header.name
'Next Column
headerCol = headerCol + 1
next header
'Copy the results of the sql statement, stored in the recordset, into the To sheet
wsTo.Range("A2").CopyFromRecordset rs
'close it up
rs.Close
objConn.Close
'Remove that tmp workbook
Kill strFileName
End Sub
SELECT Number,UpDown,FYE,GL_SEG_CD,ACCTNUMBER,CODE,sum(Amount1), sum(amount2) FROM table GROUP BY Number,UpDown,FYE,GL_SEG_CD,ACCTNUMBER,CODE? Doing this with VBA is possible, but ugh... the writing and debugging and slowness and unexpected wonkiness... it's a recipe for hairloss and heartburn.