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
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&")")
Click OK.
Use ARRMODE like a worksheet function. The reference to the cell in column A on the same row is built in.
=ARRMODE
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.