söndag 5 augusti 2012

Prime Number

Function to create prime number
Syntax =PRIME(Starting Number, Ending Number)

Private Function PRIME(St, En As Long)
Dim Ans As String
For x = St To En
    For y = 2 To x - 1
        If x Mod y = 0 Then GoTo 20:
    Next y
    Ans = Ans & x & ","
20:
Next x
PRIME = Ans
End Function

Link: ExcelForum

Update to verify a Prime:
=AND(MOD(A2;ROW(INDIRECT("2:"&INT(SQRT(A2))))))
Link: Chandoo.org

Dax in Action by Alberto Ferrari

Video - Data Mining 2012 with Microsoft Excel 2010 and PowerPivot and Dax

lördag 17 mars 2012

Excel Sort Function

Excel Sort Function.

Link
-----
This one is simple but not perfect function since two rows could have the same value.
It can be differentiated by adding cell.Value&(10^-9*ROW()).

Function Sortme(miRango As Range, Optional ByVal Order As Integer) As String

If Order = 0 Then Order = 1


For Each cell In miRango
    temp1 = Application.WorksheetFunction.CountIf(miRango, "<=" & cell.Value)
    If Order = temp1 Then Exit For
Next cell


Sortme = cell.Value
End Function

Reference: Link