Sorting and totaling of data in rows, Excel

westcap

New Member
Joined
Nov 24, 2009
Messages
3
:confused: Is there anyone who can sort information in an infinite number of columns and an infinite number of rows by information contained in each row? Some rows will contain only one column and others will have several columns.
Additionally, after the sort, I would like to total the number of like rows and insert that total in column "A" in the front of the rows, deleting all but one of the like rows. Also, there is data in parentheses that I would like to add together, per row and insert the sum in column "B" at the front of the row.
I have attached before and after files.
Thanks for any help. I have spent a lot of time trying to figure this out, but I'm not savvy enough to do it. And if I didn't explain this well enough, I'll try to clarify.
Before sort:
****** http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8"><title></title>****** name="GENERATOR" content="OpenOffice.org 3.1 (Win32)"><style> <!-- BODY,DIV,TABLE,THEAD,TBODY,TFOOT,TR,TH,TD,P { font-family:"Arial"; font-size:x-small } --> </style> <table border="0" cellspacing="0" cols="6" frame="VOID" rules="NONE"> <colgroup><col width="86"><col width="86"><col width="86"><col width="86"><col width="86"><col width="86"></colgroup> <tbody> <tr> <td width="86" align="LEFT" height="17">102249(2)</td> <td width="86" align="LEFT">102250(2)</td> <td width="86" align="LEFT">102445(1)</td> <td width="86" align="LEFT">102251(2)</td> <td width="86" align="LEFT">
</td> <td width="86" align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102131(2)</td> <td align="LEFT">102442(1)</td> <td align="LEFT">102445(1)</td> <td align="LEFT">102252(1)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102249(1)</td> <td align="LEFT">102250(1)</td> <td align="LEFT">102131(2)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102120(1)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102131(2)</td> <td align="LEFT">101773(1)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102120(1)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102251(2)</td> <td align="LEFT">102252(2)</td> <td align="LEFT">102442(1)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102120(1)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102251(1)</td> <td align="LEFT">102252(1)</td> <td align="LEFT">102250(1)</td> <td align="LEFT">102249(1)</td> <td align="LEFT">101890(1)</td> <td align="LEFT">101891(1)</td> </tr> <tr> <td align="LEFT" height="17">102249(3)</td> <td align="LEFT">102251(1)</td> <td align="LEFT">102445(1)</td> <td align="LEFT">102250(1)</td> <td align="LEFT">102253(1)</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102249(3)</td> <td align="LEFT">102445(1)</td> <td align="LEFT">102253(1)</td> <td align="LEFT">102251(1)</td> <td align="LEFT">102250(1)</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102249(1)</td> <td align="LEFT">102131(2)</td> <td align="LEFT">102250(1)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td align="LEFT" height="17">102250(2)</td> <td align="LEFT">102251(2)</td> <td align="LEFT">102445(1)</td> <td align="LEFT">102249(1)</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> </tbody> </table>

After sort:

****** http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8"><title></title>****** name="GENERATOR" content="OpenOffice.org 3.1 (Win32)"><style> <!-- BODY,DIV,TABLE,THEAD,TBODY,TFOOT,TR,TH,TD,P { font-family:"Arial"; font-size:x-small } --> </style> <table border="0" cellspacing="0" cols="8" frame="VOID" rules="NONE"> <colgroup><col width="86"><col width="86"><col width="86"><col width="86"><col width="86"><col width="86"><col width="86"><col width="86"></colgroup> <tbody> <tr> <td sdval="1" sdnum="1033;" width="86" align="CENTER" height="17">1</td> <td sdval="3" sdnum="1033;" width="86" align="CENTER">3</td> <td width="86" align="LEFT">101773(1)</td> <td width="86" align="LEFT">102131(2)</td> <td width="86" align="CENTER">
</td> <td width="86" align="CENTER">
</td> <td width="86" align="LEFT">
</td> <td width="86" align="LEFT">
</td> </tr> <tr> <td sdval="1" sdnum="1033;" align="CENTER" height="17">1</td> <td sdval="6" sdnum="1033;" align="CENTER">6</td> <td align="LEFT">101890(1)</td> <td align="LEFT">101891(1)</td> <td align="LEFT">102249(1)</td> <td align="LEFT">102250(1)</td> <td align="LEFT">102251(1)</td> <td align="LEFT">102252(1)</td> </tr> <tr> <td sdval="3" sdnum="1033;" align="CENTER" height="17">3</td> <td sdval="1" sdnum="1033;" align="CENTER">1</td> <td align="LEFT">102120(1)</td> <td align="CENTER">
</td> <td align="CENTER">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> <td align="LEFT">
</td> </tr> <tr> <td sdval="2" sdnum="1033;" align="CENTER" height="17">2</td> <td sdval="4" sdnum="1033;" align="CENTER">4</td> <td align="LEFT">102131(2)</td> <td align="LEFT">102249(1)</td> <td align="LEFT">102250(1)</td> <td align="CENTER">
</td> <td align="CENTER">
</td> <td align="LEFT">
</td> </tr> <tr> <td sdval="1" sdnum="1033;" align="CENTER" height="17">1</td> <td sdval="5" sdnum="1033;" align="CENTER">5</td> <td align="LEFT">102131(2)</td> <td align="LEFT">102252(1)</td> <td align="LEFT">102442(1)</td> <td align="LEFT">102445(1)</td> <td align="CENTER">
</td> <td align="CENTER">
</td> </tr> <tr> <td sdval="1" sdnum="1033;" align="CENTER" height="17">1</td> <td sdval="6" sdnum="1033;" align="CENTER">6</td> <td align="LEFT">102249(1)</td> <td align="LEFT">102250(2)</td> <td align="LEFT">102251(2)</td> <td align="LEFT">102445(1)</td> <td align="LEFT">
</td> <td align="CENTER">
</td> </tr> <tr> <td sdval="1" sdnum="1033;" align="CENTER" height="17">1</td> <td sdval="7" sdnum="1033;" align="CENTER">7</td> <td align="LEFT">102249(2)</td> <td align="LEFT">102250(2)</td> <td align="LEFT">102251(2)</td> <td align="LEFT">102445(1)</td> <td align="CENTER">
</td> <td align="CENTER">
</td> </tr> <tr> <td sdval="2" sdnum="1033;" align="CENTER" height="17">2</td> <td sdval="7" sdnum="1033;" align="CENTER">7</td> <td align="LEFT">102249(3)</td> <td align="LEFT">102250(1)</td> <td align="LEFT">102251(1)</td> <td align="LEFT">102253(1)</td> <td align="LEFT">102445(1)</td> <td align="LEFT">
</td> </tr> <tr> <td sdval="1" sdnum="1033;" align="CENTER" height="17">1</td> <td sdval="5" sdnum="1033;" align="CENTER">5</td> <td align="LEFT">102251(2)</td> <td align="LEFT">102252(2)</td> <td align="LEFT">102442(1)</td> <td align="CENTER">
</td> <td align="CENTER">
</td> <td align="LEFT">
</td> </tr> </tbody> </table>
<table width="30" border="0" cellspacing="0" cols="6" frame="VOID" height="30" rules="NONE"><tbody><tr><td width="86" align="LEFT" height="17">
</td><td width="86" align="LEFT">
</td><td width="86" align="LEFT">
</td><td width="86" align="LEFT">
</td><td width="86" align="LEFT">
</td><td width="86" align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td></tr><tr><td align="LEFT" height="17">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td><td align="LEFT">
</td> </tr> </tbody> </table>
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi, Try this on your trial Data first, I'm not sure how it will handle a Large number of Rows
Nb:- The code assumes your data starts "A1", Results start sheet (2) "A1".

Code:
[COLOR="Navy"]Sub[/COLOR] MG25Nov55
[COLOR="Navy"]Dim[/COLOR] Ray() [COLOR="Navy"]As[/COLOR] Variant, Dn [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] i [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] j [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] p, ACRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, m [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] s [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Temp2, Coltxt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] nRay, Q, Scp
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
ReDim Ray(1 To Rng.Count)
ReDim nRay(1 To Rng.Count)
[COLOR="Navy"]For[/COLOR] i = 1 To Rng.Count
 [COLOR="Navy"]Set[/COLOR] ACRng = Range(Range("A" & i), Cells(i, Columns.Count).End(xlToLeft))
    ReDim p(1 To ACRng.Count)
        Ray(i) = p
    [COLOR="Navy"]For[/COLOR] j = 1 To UBound(p)
        Ray(i)(j) = Cells(i, j)
    [COLOR="Navy"]Next[/COLOR] j
[COLOR="Navy"]For[/COLOR] m = 1 To UBound(p)
   [COLOR="Navy"]For[/COLOR] s = m To UBound(p)
   [COLOR="Navy"]If[/COLOR] Ray(i)(s) < Ray(i)(m) [COLOR="Navy"]Then[/COLOR]
            Temp2 = Ray(i)(m)
                Ray(i)(m) = Ray(i)(s)
                  Ray(i)(s) = Temp2
         [COLOR="Navy"]End[/COLOR] If
   [COLOR="Navy"]Next[/COLOR] s
[COLOR="Navy"]Next[/COLOR] m
[COLOR="Navy"]Next[/COLOR] i
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] Dn = 1 To UBound(Ray)
    Coltxt = ""
    [COLOR="Navy"]For[/COLOR] ac = 1 To UBound(Ray(Dn))
        Coltxt = Coltxt & Ray(Dn)(ac)
    [COLOR="Navy"]Next[/COLOR] ac
        [COLOR="Navy"]If[/COLOR] Coltxt <> "" [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]If[/COLOR] Not .Exists(Coltxt) [COLOR="Navy"]Then[/COLOR]
                n = n + 1
                .Add Coltxt, Array(n, 1)
                    ReDim Scp(1 To UBound(Ray(Dn)) + 2)
                    nRay(n) = Scp
                    nRay(n)(1) = 1: nRay(n)(2) = UBound(Ray(Dn))
            [COLOR="Navy"]For[/COLOR] ac = 1 To UBound(Ray(Dn))
                nRay(n)(ac + 2) = Ray(Dn)(ac)
            [COLOR="Navy"]Next[/COLOR] ac
        [COLOR="Navy"]Else[/COLOR]
            Q = .Item(Coltxt)
            Q(1) = Q(1) + 1
            nRay(Q(0))(1) = Q(1)
            .Item(Coltxt) = Q
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]For[/COLOR] Dn = 1 To n
    [COLOR="Navy"]For[/COLOR] ac = 1 To UBound(nRay(Dn))
         Sheets("Sheet2").Cells(Dn, ac).Value = nRay(Dn)(ac)
    [COLOR="Navy"]Next[/COLOR] ac
 [COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thanks Mick. I get an error and I'm sure it's because of my ignorance. The error highlights "Range" in Line 2. The error reads: "BASIC syntax error. Unknown data type Range.
I'm a novice with this Macros thing.

Jon
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

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