+ Reply to Thread
Results 1 to 5 of 5

Convert numeric part of text to number

  1. #1
    davegb
    Guest

    Convert numeric part of text to number

    I am combining 2 lists in 2 columns in XL. The index in both lists is
    in the format: 01-Adams. There is one for each county in the state. I
    want to know how to convert the 01 text part to a numeric value to
    compare to another one and determine where they should be in a table.
    If I do a

    strOrigCtyNo = Right(strOrig, Len(strOrig) + 2)

    I believe it will give me the first 2 characters of the code. How do I
    convert them to an integer constant to compare them, or do I even have
    to? If I remember right from my old programming days, comparing numbers
    in ASCII sometimes gives different results from comparing numbers. Is
    that still true in VBA? What is the best way to proceed here?
    Thanks again!


  2. #2
    Jim Thomlinson
    Guest

    RE: Convert numeric part of text to number

    in VBA there are functions CInt, CDbl, ... which convert text to value. You
    should be albe to use CInt to convert teh first two digits to an number.
    --
    HTH...

    Jim Thomlinson


    "davegb" wrote:

    > I am combining 2 lists in 2 columns in XL. The index in both lists is
    > in the format: 01-Adams. There is one for each county in the state. I
    > want to know how to convert the 01 text part to a numeric value to
    > compare to another one and determine where they should be in a table.
    > If I do a
    >
    > strOrigCtyNo = Right(strOrig, Len(strOrig) + 2)
    >
    > I believe it will give me the first 2 characters of the code. How do I
    > convert them to an integer constant to compare them, or do I even have
    > to? If I remember right from my old programming days, comparing numbers
    > in ASCII sometimes gives different results from comparing numbers. Is
    > that still true in VBA? What is the best way to proceed here?
    > Thanks again!
    >
    >


  3. #3
    davegb
    Guest

    Re: Convert numeric part of text to number


    Jim Thomlinson wrote:
    > in VBA there are functions CInt, CDbl, ... which convert text to value. You
    > should be albe to use CInt to convert teh first two digits to an number.
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "davegb" wrote:
    >
    > > I am combining 2 lists in 2 columns in XL. The index in both lists is
    > > in the format: 01-Adams. There is one for each county in the state. I
    > > want to know how to convert the 01 text part to a numeric value to
    > > compare to another one and determine where they should be in a table.
    > > If I do a
    > >
    > > strOrigCtyNo = Right(strOrig, Len(strOrig) + 2)
    > >
    > > I believe it will give me the first 2 characters of the code. How do I
    > > convert them to an integer constant to compare them, or do I even have
    > > to? If I remember right from my old programming days, comparing numbers
    > > in ASCII sometimes gives different results from comparing numbers. Is
    > > that still true in VBA? What is the best way to proceed here?
    > > Thanks again!
    > >
    > >


    Thanks, Jim!


  4. #4
    Tom Ogilvy
    Guest

    Re: Convert numeric part of text to number

    if the first two digits are on the left side of the string, I don't think
    this is what you want:
    strOrigCtyNo = Right(strOrig, Len(strOrig) + 2)


    strOrigCtyNo = Left(strOrig,2)

    a way to do the conversion would be

    Dim lngOrigCityNo as Long
    lngOrigCityNo = Left(strOrig,2)

    --
    Regards,
    Tom Ogilvy

    "davegb" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Jim Thomlinson wrote:
    > > in VBA there are functions CInt, CDbl, ... which convert text to value.

    You
    > > should be albe to use CInt to convert teh first two digits to an number.
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "davegb" wrote:
    > >
    > > > I am combining 2 lists in 2 columns in XL. The index in both lists is
    > > > in the format: 01-Adams. There is one for each county in the state. I
    > > > want to know how to convert the 01 text part to a numeric value to
    > > > compare to another one and determine where they should be in a table.
    > > > If I do a
    > > >
    > > > strOrigCtyNo = Right(strOrig, Len(strOrig) + 2)
    > > >
    > > > I believe it will give me the first 2 characters of the code. How do I
    > > > convert them to an integer constant to compare them, or do I even have
    > > > to? If I remember right from my old programming days, comparing

    numbers
    > > > in ASCII sometimes gives different results from comparing numbers. Is
    > > > that still true in VBA? What is the best way to proceed here?
    > > > Thanks again!
    > > >
    > > >

    >
    > Thanks, Jim!
    >




  5. #5
    davegb
    Guest

    Re: Convert numeric part of text to number

    Thanks again, Tom!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1