PDA

View Full Version : Solved: Digits in number



Aero
05-06-2010, 08:04 AM
I'm trying to figure out the digits in a number,
Like 4096 has 4 digits, 16 has 2 digits etc...

I'm trying this with Len(number) but for 4096 it gives me 2, for 16 it gives me 2..

So i'm guessing this is not the way to do this.. How can i do this?

lynnnow
05-06-2010, 08:59 AM
I tried the len function and it works fine. Are you using the number directly or a reference to a cell. If it is a reference to a cell, make sure the reference is correct.

HTH

Lincoln

Aero
05-06-2010, 09:09 AM
Sub Test1()
Dim wrong As Long
Dim wrong2 As Long
wrong = ActiveSheet.Range("C1")
wrong2 = 16

Debug.Print wrong
Debug.Print Len(wrong)
Debug.Print "---"
Debug.Print wrong2
Debug.Print Len(wrong2)
End Sub Prints this in the Immediate Window:
16
4
---
16
4

mdmackillop
05-06-2010, 09:24 AM
123456789 also returns 4. Convert them to strings


Option Explicit
Sub Test1()
Dim wrong As Long
Dim wrong2 As Long
wrong = ActiveSheet.Range("C1")
wrong2 = 16
Debug.Print wrong
Debug.Print Len(CStr(wrong))
Debug.Print "---"
Debug.Print wrong2
Debug.Print Len(CStr(wrong2))
End Sub

Aero
05-06-2010, 09:27 AM
123456789 also returns 4. Convert them to strings


Option Explicit
Sub Test1()
Dim wrong As Long
Dim wrong2 As Long
wrong = ActiveSheet.Range("C1")
wrong2 = 16
Debug.Print wrong
Debug.Print Len(CStr(wrong))
Debug.Print "---"
Debug.Print wrong2
Debug.Print Len(CStr(wrong2))
End Sub



That does the trick indeed, now it works :)
Thanks!