JennyBorlin
New Member
- Joined
- Mar 19, 2018
- Messages
- 4
Hi!
I am new to both Excel and vba. I have data for a test, where the current is logged in one column. In the beginning of the test, the current is low, after a while the current has risen (middlestage), and at the end of the test it is going to zero.
How do I compare two adjacent numbers througout a column?
Can I use the name of a cell as a variable in code? That is, calculate a variable with the with the same name as the cell and get the value to that cell.
What I want, is to get the row (Testrowstart) where the current has risen and the test is in its middlestage. In order to do this, I have written the code below. The code is supposed to get the absolute difference between to adjacent numbers in a column, throughout the column, and check if the difference is greater than a certain number, and then return the row number where this happens.
When I try the code, I have a cell that I renamed to Testrowstart where I put my user defined function. But I get #VALUE !, so what am I doing wrong?
Thanks!
I am new to both Excel and vba. I have data for a test, where the current is logged in one column. In the beginning of the test, the current is low, after a while the current has risen (middlestage), and at the end of the test it is going to zero.
How do I compare two adjacent numbers througout a column?
Can I use the name of a cell as a variable in code? That is, calculate a variable with the with the same name as the cell and get the value to that cell.
What I want, is to get the row (Testrowstart) where the current has risen and the test is in its middlestage. In order to do this, I have written the code below. The code is supposed to get the absolute difference between to adjacent numbers in a column, throughout the column, and check if the difference is greater than a certain number, and then return the row number where this happens.
When I try the code, I have a cell that I renamed to Testrowstart where I put my user defined function. But I get #VALUE !, so what am I doing wrong?
Thanks!
Code:
' 2018-03-19
'
' Returns the row where the test enters middle stage
'
'
Function Testrowstart(WorkRng As Range) As Integer
'Testrowstart = 0
Dim column As Variant
column = WorkRng.Value
' Test two values at the time in whole column
' If the difference is larger than 15, the test has entered middle stage
For i = 1 To UBound(column, 1)
' If difference between element i and (i-1) is larger than 15, set
' Testrowstart to i
If i > 1 Then
If VBA.Abs(column(i) - column(i - 1)) > 15 Then
Testrowstart = i
End If
End If
Next
End Function