Consulting

Results 1 to 4 of 4

Thread: Need help for "Format" function

  1. #1

    Need help for "Format" function

    Hi,

    I have a question regarding the format function.

    My requirement to verify an ID and fetch data from another sheet corresponding to that ID.

    Hence here I need to format a number which is seen as 1-23456 or (1)23456 to 123456 as that will help me for comparison.
    I tried the code below, however that is not giving me the results anticipated.

    If (IsNumeric(ActiveSheet.Range("H" & lngCtr))) Then
    ActiveSheet.Range("H" & lngCtr) = _
    Format(ActiveSheet.Range("H" & lngCtr), "000000")
    End If


    Can anyone give me further inputs?

    Thanks in advance!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    If (IsNumeric(ActiveSheet.Range("H" & lngCtr))) Then

    With ActiveSheet.Range("H" & lngCtr)

    .Value = Replace(Replace(Replace(.Value, _
    "-", ""), _
    "(", ""), _
    ")", "")
    End With
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks for the reply...When I tried ID as 1-23456 or (1)23456, I am still getting same result.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I missed the IF bit, which stops it working because the value is not numeric

    [vba]

    With ActiveSheet.Range("H" & lngCtr)

    .Value = Replace(Replace(Replace(.Value, _
    "-", ""), _
    "(", ""), _
    ")", "")
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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