Find MAX number in range formatted at TEXT

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
Hi there, I know that the answer to this is staring me in the face, but I can't get my brain into gear this morning

I have a range (I182:I186) which is reflecting dates from other sheets (date formatted 20180116). This range is formatted as TEXT as the reference cells are also formatted as TEXT (generated via vba) - I cannot change this...

so I have a range which looks like:

20180110
20180101
20180108
20180116
20180109

I thought I could use:

Code:
=MAX(I182:I186) // this cell is formatted as GENERAL

to simply return the largest number, but it just returns 0, but should be returning 20180116

What am I doing wrong? My brain hurts :(
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
try this, enter with Ctrl-Shift-Enter

=MAX((I182:I186)*1)
 
Upvote 0
FormR, you are a STAR! Works perfectly!

What is happening here? I've never used AGGREGATE before
 
Upvote 0
What is happening here? I've never used AGGREGATE before

Hi - a couple of notes:
1. Aggregate() with a function num of 14 can handle array processing without the need for CSE
2. In Excel when we attempt to perform an arithmetic operation on text, if it can, Excel will convert that text to a number and then perform the calculation

So we add a zero to each cell in the range with 0+I182:I186 which converts the text to a number without changing it to a different number. Then the arguments (14, 6) used in Aggregate() tell that function to get the largest k value (specificed in the last paramter) and to ignore any errors (just in case there is some text in the range that can't be converted to a number)
 
Upvote 0
Just bumped into another problem with the same cells...

I want to use my 'result cell' as part of a VLOOKUP on the same range... is it not working because of the text formatting?

Code:
=VLOOKUP(AGGREGATE(14,6,0+I182:I186,1), I182:K186, 3)

it just returns #N/A (this cell is formatted GENERAL)
 
Upvote 0
Try the amendments in red to convert the numerical result of the aggregate function back to text.

Code:
=VLOOKUP([COLOR=#ff0000][B]""&[/B][/COLOR]AGGREGATE(14,6,0+I182:I186,1), I182:K186, 3)
 
Upvote 0
Hi there FormR, sorry to bother you again with this problem, but I have just noticed that there is an error somewhere and I cannot find it for the life of me...

I have simulated the problem in a seperate workbook and uploaded it to my server: http://www.bluecustard.co.uk/AGGREGATE issue.xlsm

The top left box contains the rawdates (formatted as text) and beneath is a copy for 'copy & paste'

It seems to work fine when date 1 or 2 are lower values (earlier dates), but as soon as they are higher, the result of the VLOOKUP defaults to 5, even though the aggregate value is showing correctly....

Can you see where I am going wrong? this has bee driving me bonkers. I've treble-checked the formatting of all the boxes and I cannot see anything out of place

I really appreciate your help FormR

Regards

Rob
 
Upvote 0
Can you see where I am going wrong?

Hi, for an exact match you need to set the "Range_Lookup" paramater of the VLOOKUP() to False or Zero - i.e. change the D11 formula to:

=VLOOKUP(D9,D4:F8, 3,0)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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