Finding 1st and 2nd highest values from a series of variables

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,812
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am looking for some assistance in compiling some code to complete this task.

I have this code:
Code:
    ttl_trns = WorksheetFunction.CountIf(ws_core.Range("E:E") = "*T")
    ttl_trns_hp = WorksheetFunction.CountIfs(ws_core.Range("E:E") = "*T", ws_core.Range("J:J") = "HP")
    ttl_trns_rp = WorksheetFunction.CountIfs(ws_core.Range("E:E") = "*T", ws_core.Range("J:J") = "RP")
    ttl_trns_wp = WorksheetFunction.CountIfs(ws_core.Range("E:E") = "*T", ws_core.Range("J:J") = "WP")

Untested, I hope it will return the total number of occurrences of column E values ending in "T" and the value in column J equaling "HP", "RP", and "WP" respectively.

Consider these sample results ...

ttl_trns_hp = 3
ttl_trns_rp = 0
ttl_trns_wp = 1

Of these three values, I need to find the highest value and who it belongs to. In this case, 3 is the highest value and it represents data with column J = "HP"
then ...
I need to find the second highest value, and to who it belongs. In this case, 1 belonging to WP.

I would welcome any suggestions on how to make this work efficiently.
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,812
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Correction on my code so far:
Code:
    ttl_trns = WorksheetFunction.CountIf(ws_core.Range("E:E"), "*T")
    ttl_trns_hp = WorksheetFunction.CountIfs(ws_core.Range("E:E"), "*T", ws_core.Range("J:J"), "HP")
    ttl_trns_rp = WorksheetFunction.CountIfs(ws_core.Range("E:E"), "*T", ws_core.Range("J:J"), "RP")
    ttl_trns_wp = WorksheetFunction.CountIfs(ws_core.Range("E:E"), "*T", ws_core.Range("J:J"), "WP")
 

Watch MrExcel Video

Forum statistics

Threads
1,122,549
Messages
5,596,794
Members
414,103
Latest member
imamalidadashzada

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
Top