In Cell B1:B20 fill random numbers

In Cell G1 type this formula

=INDEX(B1:B20,N(IF(1,MODE.MULT(IF(A1:A20=”North”,ROW(A1:A20)*{1,1})))))

Does your expression evaluator – return the Array that F9 returns ?

]]>Could you try switching off Smart Scrolling (Formula Explorer Settings) to see if that helps?

( I am out of the office for a few days) ]]>

This UDF uses the variable names in the R statistical package version. The code could be tightened up a bit by removing any references to weighting and possibly by using arrays in a better way in the VBA code (I have little experience using arrays and I find Excel’s terminology confusing, poorly documented, and, perhaps, inconsistent).

Public Function GiniRSV(inputRange As Range) As Double

‘ This macro is a conversion of the R statistical package code listed here:

‘ https://rdrr.io/cran/GiniWegNeg/src/R/Gini_RSV.R

‘ But all the weights are assumed to be 1 (so there is no w array).

‘ It uses (roughly) the same variable names.

‘

‘ There is also equivalent Python code listed here:

‘ https://github.com/agcopenhaver/spatial_nGINI

‘

‘ But note that I multiplied by N/(N-1) at the end since N is likely to be relatively small in a spreadsheet,

‘ so this term is needed.

‘

Dim arrayInput() As Variant

Dim arrayY As Variant

Dim C_i As Variant

Dim icount As Long

Dim i As Long

Dim N As Long

Dim num_1 As Double

Dim num_2 As Double

Dim num_3 As Double

Dim G_num As Double

Dim T_neg As Double

Dim T_pos As Double

Dim n_RSV As Double

Dim mean_RSV As Double

On Error GoTo FuncFail:

arrayInput = inputRange.Value ‘ Take the values of the range and assign to an array. This array is

‘ two-dimensional since the spreadsheet range has two dimensions.

icount = inputRange.Count

ReDim arrayY(icount – 1) ‘ Dimension a one-dimensional array of the same size

‘ as the Selection (0 to icount – 1)

i = 0

For i = 1 To icount

arrayY(i – 1) = arrayInput(i, 1) ‘ Convert the two-dimensional Selection (1xN)

Next i ‘ into a one-dimensional array of length N called arrayY

‘ Sort the inputted values in ascending order (in arrayY)

QuickSort arrayY, LBound(arrayY), UBound(arrayY)

N = 0

num_1 = 0

num_2 = 0

num_3 = 0

T_neg = 0

T_pos = 0

C_i = arrayY ‘ To create an array the same size as arrayY, we just set it equal to arrayY

‘ The actual values of this array are assigned below

For i = LBound(arrayY) To UBound(arrayY)

N = N + 1 ‘ Since the weights are all 1, this is just N + 1 so it will end up being N (=icount)

‘ — if the weights were different, this would be = N + w(i) so it would calculate the sum of w

C_i(i) = i + 1 ‘ Since the weights are all 1, this is simple:

‘ C_i looks like [1, 2, 3, 4, 5, … N]

‘ (This is the cumulative line for perfect equality)

‘ — if the weights were different, this would be = C_i(i-1) + w(i) with C(0) previously set to 0

num_1 = num_1 + (arrayY(i) * C_i(i)) ‘ This is equivalent to sum(arrayY*C_i)

num_2 = num_2 + arrayY(i) ‘ This is equivalent to sum(arrayY)

num_3 = num_3 + arrayY(i)

‘ — if the weights were different, this would be = num_3 + arrayY(i) * w(i)

If arrayY(i) < 0 Then ' If values are negative, then add them to T_neg

T_neg = T_neg + arrayY(i)

' — if the weights were different, this would be = T_neg + arrayY(i) * w(i)

Else ' If they are positive, then add them to T_pos

T_pos = T_pos + arrayY(i)

' — if the weights were different, this would be = T_pos + arrayY(i) * w(i)

End If

Next i

G_num = (2 / N ^ 2) * num_1 – (1 / N) * num_2 – (1 / N ^ 2) * num_3

n_RSV = (2 * (T_pos + (Abs(T_neg))) / N)

mean_RSV = n_RSV / 2

GiniRSV = (1 / mean_RSV) * G_num

GiniRSV = GiniRSV * N / (N – 1) ' If N is very large, then N/(N-1) approaches 1 and this line can be eliminated

Exit Function

FuncFail:

GiniRSV = CVErr(xlErrValue)

End Function

Sub QuickSort(arr As Variant, first As Long, last As Long)

' from https://excelmacromastery.com/excel-vba-array/

Dim vCentreVal As Variant, vTemp As Variant

Dim iTempLow As Long

Dim iTempHi As Long

iTempLow = first

iTempHi = last

vCentreVal = arr((first + last) \ 2)

Do While iTempLow <= iTempHi

Do While arr(iTempLow) < vCentreVal And iTempLow < last

iTempLow = iTempLow + 1

Loop

Do While vCentreVal first

iTempHi = iTempHi – 1

Loop

If iTempLow <= iTempHi Then

' Swap values

vTemp = arr(iTempLow)

arr(iTempLow) = arr(iTempHi)

arr(iTempHi) = vTemp

' Move to next positions

iTempLow = iTempLow + 1

iTempHi = iTempHi – 1

End If

Loop

If first < iTempHi Then QuickSort arr, first, iTempHi

If iTempLow < last Then QuickSort arr, iTempLow, last

End Sub

The Hoover Index (or Robin Hood Index ), defined as the portion of the total that must be redistributed to create equality, provides another easy-to-calculate way of measuring inequality that focuses more on riches at the top. Here is an array formula to calculate it:

{=0.5 * SUM( ABS(selectedCells – AVERAGE(selectedCells) ) ) / SUM(selectedCells)}

This measure normally ranges from 0 (full equality) to 1 (all income/wealth concentrated in one set of hands), but like the Gini coefficient, it can be greater than 1 when the negative wealth (debt) or negative income greatly reduces the total. For this measure, I'm not sure if that is a problem since it is true that more than the total must be redistributed to create an equal society.

]]>Dim Txt As String, Letters() As String

Txt = StrConv(Range(“B6”), vbUnicode)

Letters = Split(Left(Txt, Len(Txt) – 1), Chr(0))

Although I would point out that you can produce the same Letters array as above with this single line of code…

Letters = Evaluate(“TRANSPOSE(MID(B6,ROW(1:” & LEN(Range(“B6”).Value) & “),1))”)

where Letters would be declared as a Variant for it.

]]>You had the true answer here – Tables and tables syntax – Did the rest of the guys get it? ]]>

The following formula is sued on upto 52 entries per row for 30 rows (weekly data input calculation)

=IF(ISBLANK(INDIRECT(“R[-1]C”,FALSE)),”ERROR”, IF(INDIRECT(“R[-1]C”,FALSE)>INDIRECT(“R[-1]C[1]”,FALSE),IF(ISBLANK(INDIRECT(“R[-1]C13″,FALSE)),”ERROR”,INDIRECT(“R[-1]C[1]”,FALSE)+INDIRECT(“R[-1]C13”,FALSE)-INDIRECT(“R[-1]C”,FALSE)),INDIRECT(“R[-1]C[1]”,FALSE)-INDIRECT(“R[-1]C”,FALSE)))

]]>