Hi,
I am trying to loop through some data and apply tests to it (i.e. if values are above/below certain input thresholds then paste a 1 or 0 into another part of the workbook). Unfortunately my code below doesn't appear to be working but I'm not getting anywhere debugging - can anyone please help/suggest where I have gone wrong?
Thanks
I am trying to loop through some data and apply tests to it (i.e. if values are above/below certain input thresholds then paste a 1 or 0 into another part of the workbook). Unfortunately my code below doesn't appear to be working but I'm not getting anywhere debugging - can anyone please help/suggest where I have gone wrong?
Thanks
VBA Code:
Sub flag_analysis()
Application.ScreenUpdating = False
Dim data_set As Variant
data_set = Sheets("Data").Range("A5:F20").Value
Dim i As Long, flag_activation As Long
flag1_level = Sheets("Inputs").Range("D3") 'this is my first test - an input with the threshold level (set to 40)
flag1_level = Sheets("Inputs").Range("D4") 'this is the second test - an input which is a percentagee e.g. 10%
For i = 1 To UBound(data_set, 1)
flag1 = data_set(i, 5) 'this is the data I am applying my first test to
flag2 = data_set(i, 6) ' this is the data I am applying my second test to
If (IsNumeric(flag1) And flag1 >= flag1_level) Or (IsNumeric(flag2) And flag2 >= flag2_level) Then 'if the data is numeric (to avoid any cells with errors in them) and if either the first or the second test is satisfied then...
flag_activation = 1 'set the flag equal to 1 (I am not using booleans because I want to add the number of flags later)
Else: flag_activation = 0 'else set the flag equal to zero
Sheets("Flags").Range("E" & i + 4) = flag_activation 'copy the flag value into the sheet Flags
End If
flag_activation = 0 'reset the flag at zero for the next loop
Next i
End Sub