简体   繁体   中英

How to calculate the mode of an array stored in a single cell in excel?

I'm new to excel, trying to calculate the mode of an array, but that array is stored in a single cell. For example, I'm storing an array(0,1,2,3,4,2,3,3,4) into cell A1 and trying to find the mode of that array. I tried MODE(A1) function, but it seems doesn't work. Is there any good recommendation? I heard it can be achieved by VBA, but I'm a noob to excel, is there any good and simple tutorial could achieve this goal? Appreciate if someone could help with this, thx:)

There is a secret function called Evaluate that can take a formula constructed from concatenated strings and produce a result equivalent to that formula being used on a worksheet.

In your case, you want to build a formula that treats your string of delimited numbers as an array of real numbers so the target would look like this.

=MODE(0,1,2,3,4,2,3,3,4)

A User Defined Function can bring this functionality to the worksheet.

Option Explicit

Function arrayMode(str As String)

    arrayMode = Application.Evaluate("MODE(" & str & ")")

End Function

enter image description here

Evaluate can also be accessed through a Defined Name. Select B2 then choose Formulas, Defined Names, Define Name. Give it a name (eg ARRMODE) and use the folllowing for the Referes to:

=Evaluate("MODE("&$A2&")")

enter image description here

Click OK.

Use ARRMODE like a worksheet function. The reference to the cell in column A on the same row is built in.

=ARRMODE

enter image description here

In A2 enter:

=IFERROR(--TRIM(MID(SUBSTITUTE($A1,",",REPT(" ",999)),COLUMNS($A:A)*999-998,999)),"")

and copy across. Then in A3 enter:

=MODE(2:2)

在此输入图像描述

(You can avoid all the "helper" cells by using the EVALUATE() function)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM