Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jan 2002
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro inserts . (97 SR1)

    I have a spreadsheet with a column of ICD-9 codes. These are medical diagnoses codes. For some reason none of them have the period inserted in them. I need a macro that says if the cell is 5 characters long, insert a period after the 3rd character then change the number of decimal places to 2. I can do all of the rest by hand. This is a tough one because an ICD-9 code can look like any of the following: 522, 622.0, 722.00, 25.0. At least I can do the 5 character ones and set the decimal place correctly

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro inserts . (97 SR1)

    The code below should do what you are asking. However, unless you need to do arithmetic with these codes, you should convert them to text - keeping them as numbers is asking for trouble.

    <pre>Public Sub FixCodes()
    Dim oCell As Range
    For Each oCell In Selection
    If Len(oCell) = 5 Then
    oCell.Value = oCell.Value / 100
    oCell.NumberFormat = "#,##0.00"
    End If
    Next oCell
    End Sub
    </pre>

    Legare Coleman

  3. #3
    Star Lounger
    Join Date
    Jan 2002
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro inserts . (97 SR1)

    You're right. Some of the codes start with a V so this won't work. I think I'll just have to fix this one by hand. Thanks.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Macro inserts . (97 SR1)

    Legare is right that you would be better off converting all to text; they'll still sort OK. I put this together quickly (quickly for me, I'm slow), based on Legare's code, though the ugliness is entirely my work:

    Option Explicit
    Public Sub FixCodes()
    Dim oCell As Range
    Dim strCellVal As String
    For Each oCell In Selection
    oCell.NumberFormat = "@"
    strCellVal = oCell.Value
    If IsNumeric(strCellVal) Then
    If InStr(1, strCellVal, ".") = 0 And Len(strCellVal) > 3 Then
    Select Case Len(strCellVal)
    Case Is = 5
    oCell.Value = Left(strCellVal, 3) & "." & _
    Right(strCellVal, 2)
    Case Is = 4
    oCell.Value = Left(strCellVal, 3) & "." & _
    Right(strCellVal, 1) & "0"
    End Select
    End If
    Select Case Len(strCellVal)
    Case Is = 4
    oCell.Value = Left(strCellVal, 3) & "." & Right(strCellVal, 1) & "0"
    Case Is <= 3
    oCell.Value = strCellVal & ".00"
    End Select
    End If
    Next oCell
    End Sub

    You need to test it more extensively than I have, let me know if there are bugs, check back in case I find and fix any myself. I think Non-V-Code ICDs should always be 3 digits, but I converted one & two digit numbers to add the ".00", even though they will be errors coming into your data. It's always possible that 3+ digit codes are miskeyed anyway. Those V-Codes are always a pain; any code starting with an alpha character is converted to text formatting but otherwise unchanged. I'll probably need this one day myself. Promise me you're not a claims processor. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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