Option Explicit
Function estrai(ByVal y As Double, v() As Double, c() As Double) As Integer
Dim j As Integer
If y <= v(0) Then
estrai = c(0)
Else
For j = 1 To UBound(v)
If y <= v(j) And y > v(j - 1) Then
estrai = c(j)
End If
Next
End If
End Function
Sub esercizio()
Dim k() As Double
Dim ka() As Double
Dim s1() As Double
Dim s1a() As Double
Dim s2() As Double
Dim s2a() As Double
Dim i As Integer
Dim x As Double
Dim a As Double
Dim T As Integer
Dim loris As Integer
i = 1
Do While Not IsEmpty(Cells(i, 2))
ReDim Preserve ka(i - 1)
ka(i - 1) = Cells(i, 2)
i = i + 1
Loop
i = 1
Do While Not IsEmpty(Cells(i, 5))
ReDim Preserve s1a(i - 1)
s1a(i - 1) = Cells(i, 5)
i = i + 1
Loop
i = 1
Do While Not IsEmpty(Cells(i, 8))
ReDim Preserve s2a(i - 1)
s2a(i - 1) = Cells(i, 8)
i = i + 1
Loop
i = 1
Do While Not IsEmpty(Cells(i, 1))
ReDim Preserve k(i - 1)
If i > 1 Then
k(i - 1) = Cells(i, 1) + k(i - 2)
Else
k(i - 1) = Cells(1, i)
End If
i = i + 1
Loop
i = 1
Do While Not IsEmpty(Cells(i, 4))
ReDim Preserve s1(i - 1)
If i > 1 Then
s1(i - 1) = Cells(i, 4) + s1(i - 2)
Else
s1(i - 1) = Cells(1, 4)
End If
i = i + 1
Loop
i = 1
Do While Not IsEmpty(Cells(i, 7))
ReDim Preserve s2(i - 1)
If i > 1 Then
s2(i - 1) = Cells(i, 7) + s2(i - 2)
Else
s2(i - 1) = Cells(1, 7)
End If
i = i + 1
Loop
T = InputBox("dammi un numero")
End Sub |