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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi,​
unclear as here 'p1' is the lowest …​
 
Upvote 0
Hi Marc,
just for representation purpose, I have considered p1 as the highest. It is like p1 is highest followed by p2, p3 and p4.
 
Upvote 0
just for representation purpose, I have considered p1 as the highest. It is like p1 is highest followed by p2, p3 and p4.
Do the values really look like "p1", "p2", etc, or are they really numeric?

To get the post possible help, it is advised to represent the data as it really exists. Don't try "simplify" things.
I have seen many instances where people do this, and they get an answer that works for their "simplified" example, but not for their actual data. So it doesn't really solve their problem.
 
Upvote 0
Attach at least a sample worksheet well respecting the Logic …​
 
Upvote 0
Sure for the information. I will post with the correct values. Thanks.
 
Upvote 0
I have attached a sample image.
Vehicle Type and Category Type are the available columns.
Category A is considered to be highest category followed by Category B, C, D and Category E. The highest category has to be displayed in 'Final Category Type' column.
Example,
for Vehicle B , the highest category is Category C and the value is displayed in column C.
Let me know if it makes sense.
 

Attachments

  • Sample image.png
    Sample image.png
    102.5 KB · Views: 10
Upvote 0
Is that really what your data looks like?
Then what determines the "highest" and "lowest" values?
Is it simply a matter of which comes first alphabetically?
If not, then you need to provide us with the logic for identifying highest/lowest (just explain it, in plain English).
 
Upvote 0
As I can do nothing with a picture … But obviously your highest is the lowest ! :rolleyes:
 
Upvote 0
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)
 
Upvote 0
Solution

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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