Macro to display highest value for a given range.

Harishmz

New Member
Joined
Jun 7, 2021
Messages
6
Office Version
  1. 2019
Platform
  1. Windows
Hi team,

please could you help with a macro to solve the below problem?
I have 2 columns - column 1 and column 2 with the below sample values. p1 is the highest value and p4 is the least value. Column 2 is a text column.
I want the highest value to be displayed in column 3 - "Output" based on column1.
For the range "Apples", the highest value is p1, orange it is p2 and grapes it is p4.

Column 1Column 2Output
Applesp3p1
Applesp1p1
Applesp2p1
Applesp4p1
Orangep3p2
Orangep2p2
Orangep3p2
Grapesp4p4
 
If it is really in alphabetic order, then one simple way would be to do the following:
1. Sort your data, primary sort on column A, secondary sort on column B, in ascending order.
2. Place this formula in cell C2 and copy down for all rows:
Excel Formula:
=IF(A2=A1,C1,B2)
Thank you very much for your quick response. I did try this formula and it perfectly worked. Much appreciated.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,214,812
Messages
6,121,704
Members
449,048
Latest member
81jamesacct

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