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

ABC
1Mode of transportCompany Name
2BikeTest Company 1
3CarTest Company 2
4WalkTest Company 1
5CarTest Company 3
6BikeTest Company 1
7CarTest Company 1
8CarTest Company 1
9WalkTest Company 2
10BikeTest Company 4
11CarTest Company 1

<tbody>
</tbody>

I need a table to look at all different permutations and count up the entries for each company like below.
ABC
1Mode of transportCompanies
2Bike1
3Car1
4Walk0
5Bike/Car0
6Bike/Car/Walk1
7Car/Walk1
8Bike/Walk0

<tbody>
</tbody>
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Based on Data in "A & B and reference column "D" try this for results in column "E".
Mode of transportCompany Name Mode of transportCompanies
BikeTest Company 1 Bike1
CarTest Company 2 Car1
WalkTest Company 1 Walk0
CarTest Company 3 Bike/Car0
BikeTest Company 1 Bike/Car/Walk1
CarTest Company 1 Car/Walk1
CarTest Company 1 Bike/Walk0
WalkTest Company 2
BikeTest Company 4
CarTest Company 1
<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> </tbody>

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,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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