How to Extract & Count Text Values from a Huge Range that includes Blanks and Several Instances of Each

harrypanaich

New Member
Joined
Jan 2, 2016
Messages
2
Hi there, please help me S.O.S. I have a table that lists 1000+ individual student details under columns labelled as ClassID, Name, ClassRoomNo, Subject1, Subject2, Subject3,.... Subject9. The subjects are text entries such as 'Psy', 'Latin', 'Math', 'Art', 'French', ... and so on. Each student has a different combination of one or several subjects upto a maximum of nine subjects; blanks also exist where a student may have taken up less than nine subjects. I need to reorganize the table on the fly so that I can see details of the number of students for each ClassRoomNo who have taken each of the numerous subjects. How can I do it. I have tried arrays, pivot tables and what not. I am a beginner at best.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Are you wanting to generate this table automatically, or will you create it manually and then fill in the numbers using formulae?
 
Upvote 0
Can you post sample input data and expected output or link to download workbook ?
 
Upvote 0
Assuming your table structure is similar that is shown below:


Book1
ABCDEFGHIJKL
1ClassIdNameClass Room noSub1Sub2Sub3Sub4Sub5Sub6Sub7Sub8Sub9
210ABC110AENGFRELATMATARTPSYSCTCHEBIO
311ABC211AARTPSYSCTCHEBIOENGFRELATMAT
412ABC312AFRELATMATCHEBIOENGARTPSYSCT
510ABC410AMATCHEFRELATARTENGSCT
610ABC510AARTPSYSCTCHEBIOENGFRELATMAT
710ABC610AFRELATMATCHEENGARTPSYSCT
810ABC710AMATCHEFRELATARTPSYBIOENGSCT
910ABC810AARTPSYSCTCHEBIOENGFRELATMAT
1011ABC911AFRELATMATCHEBIOENGARTPSYSCT
1112ABC1012AENGFRELATMATARTPSYSCTCHEBIO
1211ABC1111AARTPSYSCTCHEBIOENGFRELAT
1312ABC1212AFREMATCHEBIOENGARTSCT
1412ABC1312AMATCHEFRELATARTPSYBIOENGSCT
Sheet1



And I am expecting your output as this:


Book1
NOP
1Class Room NoSubCount
210AENG6
310AFRE6
410ALAT6
510AMAT6
610AART6
710APSY5
810ASCT6
910ACHE6
1010ABIO4
1111AART3
1211APSY3
1311ASCT3
1411ACHE3
1511ABIO3
1611AENG3
1711AFRE3
1811ALAT3
1911AMAT2
2012AFRE4
2112ALAT3
2212AMAT4
2312ACHE4
2412ABIO4
2512AENG4
2612AART4
2712APSY3
2812ASCT4
Sheet1


You can try this code which was provided to me by Mick somedays ago:

Code:
Sub ClassCnt()
Dim Ray As Variant, Rw As Long, Ac As Long, n As Long, Dic As Object, Q As Variant
lr = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Ray = Range("C1:L" & lr)
ReDim nray(1 To UBound(Ray, 1) * UBound(Ray, 2), 1 To 3)
nray(1, 1) = "Class Room No": nray(1, 2) = "Sub": nray(1, 3) = "Count"
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
n = 1
tt = Timer

For Rw = 2 To UBound(Ray, 1)
    For Ac = 2 To UBound(Ray, 2)
      If Len(Ray(Rw, Ac)) <> 0 Then
        If Not Dic.Exists(Ray(Rw, 1) & Ray(Rw, Ac)) Then
            n = n + 1
            nray(n, 1) = Ray(Rw, 1): nray(n, 2) = Ray(Rw, Ac): nray(n, 3) = 1
            Dic.Add Ray(Rw, 1) & Ray(Rw, Ac), Array(n, 1)
        Else
            Q = Dic(Ray(Rw, 1) & Ray(Rw, Ac))
                Q(1) = Q(1) + 1
                nray(Q(0), 3) = Q(1)
           Dic(Ray(Rw, 1) & Ray(Rw, Ac)) = Q
        
        End If
     End If
    Next Ac
Next Rw
Range("N1").Resize(n, 3) = nray
MsgBox "Code took " & Format(Timer - tt, "0.000secs")
End Sub
 
Upvote 0
Thanks Ombir, that worked. My apologies for a delayed acknowledgment. I will try and tweak it so that the output os grouped as per ClassRoomNo. Will get back as soon as I try. Am really grateful and amazed. Thanks a pile again.
 
Upvote 0

Forum statistics

Threads
1,217,309
Messages
6,135,770
Members
449,964
Latest member
ethanong89

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