+ Reply to Thread
Results 1 to 4 of 4

Problem with Type conversion- String to Int

Hybrid View

  1. #1
    Registered User
    Join Date
    10-25-2011
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    10

    Problem with Type conversion- String to Int

    Hiii all,
    I have a requiremnt where I need to convert an expression in string into Integer. I used CInt function but its givin error. Pleaseeee help .Not able to solve the issue


    I have to extract each DIGIT ( for further calculations) after combining the values in 4 different columns.Used the MID function fr that and the MID function can accept only strings.
    ( Here have shown extraction of only 3 digits to avoid complication)

    How to cnvert string to integer in this code without any error or Type MisMatch? Pleaaase help.

    
    Sub Check()
    Dim conced_num As String
    Dim res
    Dim cd As Integer
    
    For i = 4 To 8
    
    conced_num = Cells(i, 3).Value & Cells(i, 5).Value & Cells(i, 15).Value & Cells(i, 22).Value
    
    res = CInt( (Mid(conced_num, 3, 1)) ) * 89 + CInt( (Mid(conced_num,2,1)) ) * 17 + CInt( (Mid(conced_num,1,1)) ) * 16 
    
    cd = 98 - (res Mod 93)
    
     Next i
     
    End Sub

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,060

    Re: Problem with Type conversion- String to Int

    You should have no problem if all the characters are numeric.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    10-25-2011
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Problem with Type conversion- String to Int

    Nope it is highlighin the followin part in yellow color.

    res = CInt((Mid(conced_num, 3, 1))) * 89 + CInt((Mid(conced_num, 2, 1))) * 17

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Problem with Type conversion- String to Int

    You need to look in the values of
    Mid(conced_num, 3, 1)
    and
    Mid(conced_num, 2, 1)
    they probably contain text or characters that cannot be converted to integers

+ 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