Complex count next to alphabets of header group in entire column data

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

I have got 3-alphabets, 14-group is in the row 2, 3, and 4, columns S:AF

Note: Range S2:AF4, 3-alphabets is inserted manually and is not fixed so VBA should always consider the values are in range S2:AF4.

I want VBA, which counts (A, B, C and D occurrence) after the 3-alphabets groups, is find in the each columns through (C:P) and show counts results in range S7:AF10

And also highlights the cells in the column (C:P) as shown it is an optional if possible

For example...
Column "S" 3-alphabets in range S2:S4 = ABC, look ABC in to whole column "C" and count how many times has occurred after the "ABC" (A, B, C, and D) and the count of column "C" placed in to S7:S10

Column "T" 3-alphabets in range T2:T4 = ABD, look ABD in to whole column "D" and count how many times has occurred after the "ABD" (A, B, C, and D) and the count of column "C" placed in to T7:T10

Same procedure for the next columns up to column P

Sheet example...


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1
2AACABDBAAAACBA
3BBAACCCBAAAADA
4CDABBABCAAAACA
512345678910111213141234567891011121314
6
7DBBADBCADCBBCAA2312111112
8DCCADCBADBCCBAB2111121
9DAABDADACDBACAC111
10CBADCADAADDBAAD2111
11BDBDBBCABCCCAB
12DCCDCCABCABABC
13CBBDABACABCADA
14ACCDBDBABDABDB
15ABBCCCCADCADDC
16BCDBABBBDAACDB
17CADCBCDCCABADC
18AACACBCAABDBCA
19BAABBCAAADCCBB
20CAACDABBADBADD
21AAABDACDADCADC
22BABCCBACADAACB
23CACAADAABCBBBC
24BAABACBACBCCCB
25CAACBACAACAAAC
26BAAACBAABBAABA
27CBBBBDABCCABCA
28ACCDCDBDBBADAB
29AAADBCDCDCBCBD
30AAADCACBCADACD
31AAADAAACAACAAC
32ABACBAABBBABBA
33BDAADABDCDBCDA
34CDABCACCACDADA
35BCACBBABBACBDA
36CBBBCCBDCABCDB
37BCCCAACCABDBDD
38DBAABBAAADDCCC
39DCBADCBBBDDAAB
40CACBDADDCDCBBC
41BBBCCBCCACBDCA
42DDDABCBAABCDBA
43DDCBDADAACACDA
44DDADCACABABACB
45CCBCABAACACBAC
46AACABDBAAAACBA
47BBAACCCBAAAADA
48CDABBABCAAAACA
49
Sheet1


Thank you in advance

Regards,
Kishan
 
Is possible to adapt the code i provided in the thread
https://www.mrexcel.com/forum/excel...der-group-whole-column-data-fill-colours.html
to do the two tasks at once.

Try
Code:
Sub aTest()
    Dim rCrit As Range, rData As Range, rDest As Range
    Dim i As Long, j As Long, dic As Object, lGray As Long
    
    Set rCrit = Range("S2:AF4")
    Set rDest = Range("S7:AF10")
    Set rData = Range("C7:P" & Cells(Rows.Count, "C").End(xlUp).Row)
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = vbTextCompare
    lGray = RGB(192, 192, 192)
    
    For i = 1 To rData.Columns.Count
        dic("A") = Empty: dic("B") = Empty: dic("C") = Empty: dic("D") = Empty
        With rData.Columns(i)
            j = 1
            Do
                If .Cells(j) = rCrit.Columns(i).Cells(1) _
                        And .Cells(j + 1) = rCrit.Columns(i).Cells(2) _
                        And .Cells(j + 2) = rCrit.Columns(i).Cells(3) Then
                    .Cells(j).Resize(3).Interior.Color = rCrit.Columns(i).Cells(1).Interior.Color
                    
                    If .Cells(j).Offset(-1).Interior.Color = rCrit.Columns(i).Cells(1).Interior.Color Then
                            .Cells(j).Interior.Color = lGray
                    End If
                    
                    If j < rData.Rows.Count - 3 Then
                        .Cells(j + 3).Interior.Color = lGray
                        dic(.Cells(j + 3).Value) = dic(.Cells(j + 3).Value) + 1
                    End If
                    j = j + 3
                Else
                    j = j + 1
                End If
            Loop Until j > rData.Rows.Count - 2
        End With
        rDest.Columns(i) = Application.Transpose(dic.items)
    Next i
End Sub

M.
Hi Marcelo Branco, I did liked your way of colouring macro as per header colour set-up which is very practical if one get bored watching the same colour can be replaced easily.

Thank you for adding a count feature in the previous macro and making it two in one solution. It is a very fine too.

Have a nice time

Regards,
Kishan

 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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