For my code, I have the user insert a numerical value in row 1 column 6. For example the user may enter the value 45. The user then runs the macro which should spit out the number 124 into row 3 column 6; however, I am receiving an overflow error. I have posted the code below:
Sub CalculateAQI()
Dim I As Long, IL As Long, BPH As Long, BPL As Long, IH As Long, J As Long, X As Long, K As Long
Dim C As Long, V As Long
Dim L As Long
'
'User inputs a numerical value located in cell (1,6) and then runs this macro
Cells(1, 6).Value = I
If 0 <= I <= 15.4 Then
IH = 50 And IL = 0 And BPH = 12 And BPL = 0
Else
If 15.5 <= I <= 40.4 Then
IH = 100 And IL = 51 And BPH = 35.4 And BPL = 12.1
Else
If 40.5 <= I <= 65.4 Then
IH = 150 And IL = 101 And BPH = 55.4 And BPL = 35.5
Else
If 65.5 <= I <= 150.4 Then
IH = 200 And IL = 151 And BPH = 150.4 And BPL = 55.5
Else
If 150.5 <= I <= 250.4 Then
IH = 300 And IL = 201 And BPH = 250.4 And BPL = 150.5
Else
If 250.5 <= I <= 350.4 Then
IH = 400 And IL = 301 And BPH = 650 And BPL = 250.5
Else
If 350.5 <= I <= 500.4 Then
IH = 500 And IL = 401 And BPH = 650 And BPL = 250.5
End If
End If
End If
End If
End If
End If
End If
'The destination of the final numerical value should be placed in Cell(3,6)
J = (IH - IL)
K = (BPH - BPL)
X = (I - BPL)
L = CLng(J) / CLng(K)
C = CLng(L) * CLng(X)
V = CLng(C) + CLng(IL)
'Cells(3, 6).Value = ((IH - IL) / (BPH - BPL)) * (I - BPL) + IL
Cells(3, 6).Value = V
'
End Sub
My error occurs at L = CLng(j) / CLng(k). I originally has all values as integers and I attempted to use the help menu from Microsoft Excel; however, I have been banging my head against a wall for the last two days trying to make this work. If anyone could help me or provide me with some guidance, I would greatly appreciate it.
Jedit
Sub CalculateAQI()
Dim I As Long, IL As Long, BPH As Long, BPL As Long, IH As Long, J As Long, X As Long, K As Long
Dim C As Long, V As Long
Dim L As Long
'
'User inputs a numerical value located in cell (1,6) and then runs this macro
Cells(1, 6).Value = I
If 0 <= I <= 15.4 Then
IH = 50 And IL = 0 And BPH = 12 And BPL = 0
Else
If 15.5 <= I <= 40.4 Then
IH = 100 And IL = 51 And BPH = 35.4 And BPL = 12.1
Else
If 40.5 <= I <= 65.4 Then
IH = 150 And IL = 101 And BPH = 55.4 And BPL = 35.5
Else
If 65.5 <= I <= 150.4 Then
IH = 200 And IL = 151 And BPH = 150.4 And BPL = 55.5
Else
If 150.5 <= I <= 250.4 Then
IH = 300 And IL = 201 And BPH = 250.4 And BPL = 150.5
Else
If 250.5 <= I <= 350.4 Then
IH = 400 And IL = 301 And BPH = 650 And BPL = 250.5
Else
If 350.5 <= I <= 500.4 Then
IH = 500 And IL = 401 And BPH = 650 And BPL = 250.5
End If
End If
End If
End If
End If
End If
End If
'The destination of the final numerical value should be placed in Cell(3,6)
J = (IH - IL)
K = (BPH - BPL)
X = (I - BPL)
L = CLng(J) / CLng(K)
C = CLng(L) * CLng(X)
V = CLng(C) + CLng(IL)
'Cells(3, 6).Value = ((IH - IL) / (BPH - BPL)) * (I - BPL) + IL
Cells(3, 6).Value = V
'
End Sub
My error occurs at L = CLng(j) / CLng(k). I originally has all values as integers and I attempted to use the help menu from Microsoft Excel; however, I have been banging my head against a wall for the last two days trying to make this work. If anyone could help me or provide me with some guidance, I would greatly appreciate it.
Jedit