none
code returns 66 from vlookup when the correct value is 66.16667 RRS feed

  • Question

  • With Worksheets("tables")
            .Range("e18").Value = BirthYear
            Set LookupRange = .Range("a5: c108")
            NormalRetirementAge = Application.WorksheetFunction.VLookup(BirthYear, LookupRange, 3, True)
            MsgBox Excel.WorksheetFunction.Text(NormalRetirementAge, "#### ?/??")
            NormalRetirementYear = BirthYear + NormalRetirementAge

    End With

    NormalRetirementAge is dim as long

    message box returns 66 instead of 66.166667. any ideas?

    Friday, February 20, 2015 5:13 PM

Answers

  • A variable of type Long can only hold whole numbers; any decimal places are ignored. If you want to allow decimal places, declare NormalRetirementAge as Single or as Double.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by DBW5455 Tuesday, February 24, 2015 2:39 PM
    Friday, February 20, 2015 5:16 PM

All replies

  • A variable of type Long can only hold whole numbers; any decimal places are ignored. If you want to allow decimal places, declare NormalRetirementAge as Single or as Double.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by DBW5455 Tuesday, February 24, 2015 2:39 PM
    Friday, February 20, 2015 5:16 PM
  • so simple. Thank you very much. I hope one day to not need so much help, but I really appreciate yours!

    Friday, February 20, 2015 6:00 PM