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

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,235
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.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,235
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")
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,147
Messages
5,835,667
Members
430,373
Latest member
swartzfeger

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