VBA Code Between Two Values

  • Dim Age, Milage, Radius, NCB As Integer
    Age = ThisWorkbook.Sheets("Sheet1").Cells(9, 2).Value


    If Age = 45 Then ThisWorkbook.Sheets("Sheet1").Cells(9, 3).Value = 1
    If Age = (46 <= 50) Then ThisWorkbook.Sheets("Sheet1").Cells(9, 3).Value = 0.95
    If Age = (51 <= 54) Then ThisWorkbook.Sheets("Sheet1").Cells(9, 3).Value = 0.89
    If Age = (55 <= 65) Then ThisWorkbook.Sheets("Sheet1").Cells(9, 3).Value = 0.87
    If Age = (66 <= 69) Then ThisWorkbook.Sheets("Sheet1").Cells(9, 3).Value = 0.95


    This should be easy but I can't seem to solve it, How do I get the Age ranges to work between 46 and 50, 51 and 54 etc. The one for 45 works fine but every other number I enter into Cell 9, 2 brings back 0.95 as its under 69.


    Thanks
    Em

  • Re: VBA Code Between Two Values


    Select Case should do this.

  • Re: VBA Code Between Two Values


    Thanks Omp65, I've only just started writing Vba code and finding it confusing. They should just have a between sign!

  • Re: VBA Code Between Two Values


    There is a 'between'...


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!