Special sort

YANECKC

Board Regular
Joined
Jun 13, 2002
Messages
199
I want to do a special sort where columns has values STOCK RECORD and ISSUES and A. I want to sort the first cell in column A with STOCK RECORD. then next the first time ISSUES appears and then the first time A appears. It would look like
STOCK RECORD
ISSUES
A
STOCK RECORD
ISSUES
A
STOCK RECORD
ISSUES
A
STOCK RECORD
ISSUES
A

Any thoughts on how I can sort like example

Yaneckc
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I want to do a special sort where columns has values STOCK RECORD and ISSUES and A. I want to sort the first cell in column A with STOCK RECORD. then next the first time ISSUES appears and then the first time A appears. It would look like
STOCK RECORD
ISSUES
A
STOCK RECORD
ISSUES
A
STOCK RECORD
ISSUES
A
STOCK RECORD
ISSUES
A

Any thoughts on how I can sort like example

Yaneckc

If you're happy to create another column to use as the SORT ORDER...


Excel 2010
AB
1stock record1A
2a1C
3issues1B
4issues2B
5a2C
6stock record2A
7issues3B
8stock record3A
9a3C
10a4C
11issues4B
12stock record4A

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
B1=IF(TRIM(A1)="STOCK RECORD",COUNTIF(INDIRECT("$A$1:$A$"&ROW()),"STOCK RECORD")&"A",IF(TRIM(A1)="ISSUES",COUNTIF(INDIRECT("$A$1:$A$"&ROW()),"ISSUES")&"B",IF(TRIM(A1)="A",COUNTIF(INDIRECT("$A$1:$A$"&ROW()),"A")&"C","")))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

You can then sort on column
 
Upvote 0
There are 11 columns and the first one coloumn has no header name.. ACCOUNT NUMBER - 10 ADP SECURITY CUSIP SETTL DATE QTY DESC TXT DISPLAY Variable/Fixed Rate INTEREST RATE MATURITY DATE Proctor Notes COA-OFFICE_CD.
The problem is the the account number column and adp security column has to be part of the sort . The first acct in my table is "0000000109"

Yaneckc
 
Upvote 0
There are 11 columns and the first one coloumn has no header name.. ACCOUNT NUMBER - 10 ADP SECURITY CUSIP SETTL DATE QTY DESC TXT DISPLAY Variable/Fixed Rate INTEREST RATE MATURITY DATE Proctor Notes COA-OFFICE_CD.
The problem is the the account number column and adp security column has to be part of the sort . The first acct in my table is "0000000109"

Yaneckc


Could you provide a clear example of what you're looking for - perhaps some anonymised data that is representative/demonstrative of the patterns involved, and what you'd like the final output to be?
 
Upvote 0
Instead of special sort , Can I have a macro that insert 2 blanks rows if column B is not BLANK(NULL). The first blank row needs the word "ISSUES" in column A and next row is completely blank.
the excel file would look like

Vault Positions extracted form Stock Record
- ACCOUNT -ADPsecurity-CUSIP- -SETTQTY-DISCRIPTION-VARFIX-INTEREST-MATURITY -PROCTOR

STOCK RECORD-0000000109-B427050 -097373107--31.00 -BOISE CASA -VAR - 0.0 -00/00/0000-TEST DATA
ISSUES - - - - - - - - -
- - - - - - - - -
STOCK RECORD-0000000109-C000059 -216648301- 58.00 -COOPER CPY - FIX - 1.6 -00/00/0000- APPLE DATA
ISSUES - - - - - - - - -
- - - - - - - - -
STOCK RECORD-0000000182-9L50878 - - 99.00 -PACIFIC CO - FIX - 5.6 -00/00/0000- BERN DATA
ISSUES - - - - - - - - -
- - - - - - - - -

YANECKC
 
Upvote 0
Instead of special sort , Can I have a macro that insert 2 blanks rows if column B is not BLANK(NULL). The first blank row needs the word "ISSUES" in column A and next row is completely blank.


Yes!


NB: Please make sure you change the first two lines (CONSTS statements) to the correct sheet name and start row.

DataStartRow = 2 assumes Row 1 contains headers (and not data!)




Code:
Sub AddTwoRows()


    Const MyWorkSheetName = "Sheet2"
    Const DataStartRow = 2
    
    
    Dim EndRow As Integer, Cntr As Integer


    Application.ScreenUpdating = False


    With Sheets(MyWorkSheetName)


        'Get the max number of rows in the sheet by looking in column A for last piece of data.
        EndRow = .Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        
        'Work from the bottom up
        For Cntr = EndRow To DataStartRow Step -1
                    
            'Check to see if cell in Column B is blank
            If Len(Trim(.Range("B" & Cntr))) > 0 Then
                    
                'Insert two blank rows
                .Range(Cntr + 1 & ":" & Cntr + 2).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            
                'If it is NOT blank, add word "ISSUES"
                .Range("A" & Cntr + 1).Value = "ISSUES"
                
            End If
                
        Next Cntr


    End With


    Application.ScreenUpdating = True
    
    MsgBox "Task Complete", vbOKOnly, "AddTwoRows()"


End Sub


Excel 2010
ABC
1LABEL ACCOUNTADPsecurity
2STOCK RECORD109B427050
3STOCK RECORDC000059
4STOCK RECORD1829L50878
5STOCK RECORD109B427050
6STOCK RECORDB427050
7STOCK RECORD182C000059
8STOCK RECORD1099L50878
9STOCK RECORDB427050
10STOCK RECORD109C000059

<tbody>
</tbody>

becomes

Excel 2010
ABC
1LABEL ACCOUNTADPsecurity
2STOCK RECORD109B427050
3ISSUES
4
5STOCK RECORDC000059
6STOCK RECORD1829L50878
7ISSUES
8
9STOCK RECORD109B427050
10ISSUES
11
12STOCK RECORDB427050
13STOCK RECORD182C000059
14ISSUES
15
16STOCK RECORD1099L50878
17ISSUES
18
19STOCK RECORDB427050
20STOCK RECORD109C000059
21ISSUES

<tbody>
</tbody>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,349
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top