Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    311

    Unanswered: check if value is a number?

    i have some code that takes the last position of a string the strings are like :

    Fund1
    Fund69
    i created a string to hold the value
    s=...

    s will then = 1 or 69
    but its a string
    how can i check to see if this string can be converted to an integer?

    Any ideas apreciated

    Thanks

    M~

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067

    Re: check if value is a number?

    Hi Mike

    Ive put this VBA Code together for you which should solve your problem.

    Code:
    Sub CheckNumber()
        Dim S As String
        Dim I As Integer
        Dim isNumeric As Boolean
        
        isNumeric = True
        'Get value of S
        S = ActiveCell.Offset(0, -1).Value
        
        On Error GoTo NotNumeric
        'if S cannot be changed to an integer then run NotNumeric
        I = CInt(S)
        If isNumeric = True Then
            ActiveCell.Value = I
        Else
            ActiveCell.Formula = "Not Integer"
        End If
        Exit Sub
    
    NotNumeric:
        isNumeric = False
        Resume Next
        
    End Sub
    You should be able to alter this for your own needs.

    David

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •