Counting company no.s in 1 column based on criteria in another

L

Legacy 90606

Guest
working on a very large spreadsheet that has the details of lots of employees and their mode of travel to work.
I need to be able to a countif on the company name based on the criteria in another column

[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Mode of transport[/TD]
[TD]Company Name[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Bike[/TD]
[TD]Test Company 1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Car[/TD]
[TD]Test Company 2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Walk[/TD]
[TD]Test Company 1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Car[/TD]
[TD]Test Company 3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Bike[/TD]
[TD]Test Company 1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Car[/TD]
[TD]Test Company 1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Car[/TD]
[TD]Test Company 1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Walk[/TD]
[TD]Test Company 2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]Bike[/TD]
[TD]Test Company 4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]Car[/TD]
[TD]Test Company 1[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I need a table to look at all different permutations and count up the entries for each company like below.
[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Mode of transport[/TD]
[TD]Companies[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Bike[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Car[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Walk[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Bike/Car[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Bike/Car/Walk[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Car/Walk[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Bike/Walk[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Based on Data in "A & B and reference column "D" try this for results in column "E".
[TABLE="width: 507"]
<colgroup><col width="160" style="width: 120pt; mso-width-source: userset; mso-width-alt: 5688;"> <col width="158" style="width: 118pt; mso-width-source: userset; mso-width-alt: 5603;"> <col width="90" style="width: 68pt; mso-width-source: userset; mso-width-alt: 3214;"> <col width="159" style="width: 119pt; mso-width-source: userset; mso-width-alt: 5660;"> <col width="109" style="width: 82pt; mso-width-source: userset; mso-width-alt: 3868;"> <tbody>[TR]
[TD="class: xl65, width: 160, bgcolor: white"]Mode of transport[/TD]
[TD="class: xl65, width: 158, bgcolor: white"]Company Name[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl67, width: 159, bgcolor: transparent"]Mode of transport[/TD]
[TD="class: xl67, width: 109, bgcolor: transparent"]Companies[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Bike[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 1[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl68, width: 159, bgcolor: transparent"]Bike[/TD]
[TD="class: xl69, bgcolor: transparent, align: right"]1[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Car[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 2[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl68, width: 159, bgcolor: transparent"]Car[/TD]
[TD="class: xl69, bgcolor: transparent, align: right"]1[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Walk[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 1[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl68, width: 159, bgcolor: transparent"]Walk[/TD]
[TD="class: xl69, bgcolor: transparent, align: right"]0[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Car[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 3[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl68, width: 159, bgcolor: transparent"]Bike/Car[/TD]
[TD="class: xl69, bgcolor: transparent, align: right"]0[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Bike[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 1[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl68, width: 159, bgcolor: transparent"]Bike/Car/Walk[/TD]
[TD="class: xl69, bgcolor: transparent, align: right"]1[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Car[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 1[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl68, width: 159, bgcolor: transparent"]Car/Walk[/TD]
[TD="class: xl69, bgcolor: transparent, align: right"]1[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Car[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 1[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl68, width: 159, bgcolor: transparent"]Bike/Walk[/TD]
[TD="class: xl69, bgcolor: transparent, align: right"]0[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Walk[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 2[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl69, bgcolor: transparent"] [/TD]
[TD="class: xl69, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Bike[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 4[/TD]
[TD="class: xl66, width: 90, bgcolor: white"] [/TD]
[TD="class: xl69, bgcolor: transparent"] [/TD]
[TD="class: xl69, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl66, width: 160, bgcolor: white"]Car[/TD]
[TD="class: xl66, width: 158, bgcolor: white"]Test Company 1[/TD]
[TD="class: xl70, bgcolor: white"] [/TD]
[TD="class: xl69, bgcolor: transparent"] [/TD]
[TD="class: xl69, bgcolor: transparent"] [/TD]
[/TR]
</tbody>[/TABLE]

Code:
[COLOR="Navy"]Sub[/COLOR] MG05Sep47
   [COLOR="Navy"]Dim[/COLOR] Dn          [COLOR="Navy"]As[/COLOR] Range
    [COLOR="Navy"]Dim[/COLOR] Rng         [COLOR="Navy"]As[/COLOR] Range
    [COLOR="Navy"]Dim[/COLOR] Dic         [COLOR="Navy"]As[/COLOR] Object
    [COLOR="Navy"]Dim[/COLOR] Num         [COLOR="Navy"]As[/COLOR] Double
    [COLOR="Navy"]Dim[/COLOR] K           [COLOR="Navy"]As[/COLOR] Variant
    [COLOR="Navy"]Dim[/COLOR] p           [COLOR="Navy"]As[/COLOR] Variant
    [COLOR="Navy"]Dim[/COLOR] c           [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
    [COLOR="Navy"]Dim[/COLOR] Sp          [COLOR="Navy"]As[/COLOR] Variant
    [COLOR="Navy"]Dim[/COLOR] n           [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
    [COLOR="Navy"]Dim[/COLOR] rNum        [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
    [COLOR="Navy"]Dim[/COLOR] uNum        [COLOR="Navy"]As[/COLOR] Double
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
 [COLOR="Navy"]Set[/COLOR] Dic = CreateObject("Scripting.Dictionary")
    Dic.CompareMode = 1
   [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
           Num = 0
            [COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] Dn.Offset(, -1).Value
                [COLOR="Navy"]Case[/COLOR] "Bike": Num = 1
                [COLOR="Navy"]Case[/COLOR] "Car": Num = 2
                [COLOR="Navy"]Case[/COLOR] "Walk": Num = 3
            [COLOR="Navy"]End[/COLOR] Select
            
            [COLOR="Navy"]If[/COLOR] Not Dic.exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]Set[/COLOR] Dic(Dn.Value) = CreateObject("Scripting.Dictionary")
            [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]If[/COLOR] Not Dic(Dn.Value).exists(Dn.Offset(, -1).Value) [COLOR="Navy"]Then[/COLOR]
                Dic(Dn.Value).Add (Dn.Offset(, -1).Value), Num
            [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] Dn
  
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
        Dn.Offset(, 1).Value = 0: rNum = 0: Tot = 0
        Sp = Split(Dn.Value, "/")
        [COLOR="Navy"]For[/COLOR] n = 0 To UBound(Sp)
            [COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] Sp(n)
                [COLOR="Navy"]Case[/COLOR] "Bike": Num = 1
                [COLOR="Navy"]Case[/COLOR] "Car": Num = 2
                [COLOR="Navy"]Case[/COLOR] "Walk": Num = 3
            [COLOR="Navy"]End[/COLOR] Select
        rNum = rNum + Num
        [COLOR="Navy"]Next[/COLOR] n
    
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] Dic.keys
            nStr = "": uNum = 0
            [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] p [COLOR="Navy"]In[/COLOR] Dic(K)
                uNum = uNum + Dic(K).Item(p)
            [COLOR="Navy"]Next[/COLOR] p
            [COLOR="Navy"]If[/COLOR] uNum = rNum [COLOR="Navy"]Then[/COLOR] Dn.Offset(, 1).Value = Dn.Offset(, 1).Value + 1
       [COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick


www
 
Upvote 0
Thanks Mick I was hoping for some sort of formula as I'm not sure about coding
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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