Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank's Tom
its working Regards alvin "Tom Ogilvy" wrote: Function IsHappy(num As Long, _ Optional flag As Boolean = True, _ Optional cnt As Long = 1) Static orig As Long Dim n1 As Long Dim str As Long Dim tot As Long If flag Then orig = 0 End If If num < 1 Then cnt = cnt + 1 tot = 0 sStr = CStr(num) For i = 1 To Len(sStr) n1 = CLng(Mid(sStr, i, 1)) tot = tot + n1 ^ 2 Next If tot = 1 Then IsHappy = True ElseIf cnt 30 Then IsHappy = False Else If flag Then orig = tot IsHappy = IsHappy(tot, False, cnt) End If End Function -- Regards, Tom Ogilvy "alvin Kuiper" wrote in message ... Hi! I want to check if a number is a happy number a number number is like this (sorry i can't write it correct with in 2 hope you understand) Number is 19 1 in 2 + 9 in 2 = 82 8 in 2 + 2 in 2 = 68 6 in 2 + 8 in 2 = 100 1 in 2 + 0in 2 + 0in 2 = 1 This is not a Happy number Number = 24 2in2 + 4in2 = 20 2in2 + 0in2 = 4 So only when the last ciffer is one it is a happy number I can make it by using if and if and if........................... But isn't there a easy way to do this? Please help i can't see it.......... Best regards Alvin |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel Data Validation/Lookup function does function correcty | Excel Worksheet Functions | |||
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) | Excel Worksheet Functions | |||
Offset function with nested match function not finding host ss. | Excel Worksheet Functions | |||
Formatering af Dato m. klokkeslæt som et tal - speciel | Excel Worksheet Functions | |||
User-Defined Function pre-empting Built-in Function? How to undo???? | Excel Programming |