Hi again,
below is your original code with the changes I suggested. I ran it with the data you posted later and it seems to work... well there aren't any errors. I can only assume the results are what you're looking for!?
Keep us posted k :-)
Function GetVoltN(VoltN As Double)
' the function declaration above casts variable VoltN as data type Double
' as the value that is retruned when the function is called
Dim Difference As Double
Dim i As Long
Dim n As Long
Dim AvrPoints As Boolean
Dim LastRow As Long
LastRow = ActiveSheet.Range("B65536").End(xlUp).Row
For i = 0 To LastRow
n = LastRow - i
VoltN = Application.WorksheetFunction.Average(ActiveSheet.Range("B" & n & ":B" & LastRow))
Difference = VoltN - Cells(n - 1, 2)
If Difference > 0.0004 Then
AvrPoints = True
Exit For
End If
Next i
If AvrPoints = True Then
MsgBox "The point, from with the averaging starts is:_" & n
MsgBox "The value of Vn[mV] is:_" & VoltN
End If
ActiveSheet.Cells(2, 4).Value = n
ActiveSheet.Cells(2, 5).Value = VoltN
End Function
'Calculation of Vs[mV]
Function GetVoltS(VoltS As Double)
Dim i As Long
Dim AvrPoints As Boolean
Dim LastRow As Long
LastRow = ActiveSheet.Range("B65536").End(xlUp).Row
For i = 1 To LastRow
VoltS = Application.WorksheetFunction.Average(ActiveSheet.Range("B1:B" & i))
Difference = Cells(i + 1, 2) - VoltS
If Difference > 0.0004 Then
AvrPoints = True
Exit For
End If
Next i
If AvrPoints = True Then
MsgBox "The number of averaged points is:_" & i
MsgBox "The value of Vs[mV] is:_" & VoltS
End If
ActiveSheet.Cells(1, 4).Value = i
ActiveSheet.Cells(1, 5).Value = VoltS
End Function
Sub GetDeltaV()
Dim a As Double
Dim b As Double
'***we call the function which returns a value (a Double)
'***this value is passed to the named argument, our local variable, a
Call GetVoltN(a)
Call GetVoltS(b)
DeltaV = a - b
MsgBox DeltaV
End Sub