Private Sub Worksheet_Change(ByVal Target As Range)
'FOR COLUMNS "B" through "I"
' each time "YES" selected in rows 7,12,17,22,27,32....to 92
'----------------------------> userform1.show
' each time "NO" selected in rows 5,10,15,20,25,30....to 90
'----------------------------> userform2.show
Dim row_num As Integer
Dim col_num As Integer
Dim thisRow As Long
Dim thisCol As Long
Dim wsNotes As Worksheet
Const ksRange = "DataList"
Const ksTrigger = "Yes"
Const ksTriggerNo = "No"
Dim rng As Range
Set wsNotes = Sheets("Notes")
Set rng = Range(ksRange)
Dim lookup_array As Variant, output_array, Yes_Array, No_Array, Check_Value As Variant
Dim CellValue As String
If Application.Intersect(Target, rng) Is Nothing Then GoTo Worksheet_Change_Exit
If Target.Cells.Count > 1 Then GoTo Worksheet_Change_Exit
'Check_Row = Split("7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92,5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90", ",")
No_Array = Split("5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90", ",")
Yes_Array = Split("7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92", ",")
For Check_Value = LBound(Yes_Array) To UBound(Yes_Array)
If Target.Row = Yes_Array(Check_Value) Then
If LCase(Target.Value) = LCase("Yes") Then
CellValue = "Yes"
GoTo FormShow
End If
End If
Next Check_Value
For Check_Value = LBound(No_Array) To UBound(No_Array)
If Target.Row = No_Array(Check_Value) Then
If LCase(Target.Value) = LCase("No") Then
CellValue = "No"
GoTo FormShow
End If
End If
Next Check_Value
FormShow:
With Target
' YES answer to Endangered?
If LCase(CellValue) = LCase(ksTrigger) Then
lookup_array = Array(0, 7, 9, 12, 14, 17, 19, 22, 24, 27, 29, 32, 34, 37, 39, _
42, 44, 47, 49, 52, 54, 57, 59, 62, 64, 67, 69, 72, 74, 77, 79, 82, 84, 87, 89, 92)
output_array = Array(0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, _
11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18)
thisRow = Target.Row
thisCol = Target.Column
row_num = Application.WorksheetFunction.Lookup(thisRow, lookup_array, output_array)
col_num = thisCol
With UserForm1
.RowIndex = row_num + 1
.ColIndex = col_num
.Show
End With
Exit Sub
End If
' NO answer to Hunted?
If LCase(CellValue) = LCase(ksTriggerNo) Then
lookup_array = Array(0, 5, 7, 10, 12, 15, 17, 20, 22, 25, 27, 30, 32, 35, 37, _
40, 42, 45, 47, 50, 52, 55, 57, 60, 62, 65, 67, 70, 72, 75, 77, 80, 82, 85, 87, 90)
output_array = Array(0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, _
11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18)
thisRow = Target.Row
thisCol = Target.Column
row_num = Application.WorksheetFunction.Lookup(thisRow, lookup_array, output_array)
col_num = thisCol
With UserForm2
.RowIndex = (row_num * 5) + 1
.ColIndex = col_num
.Show
End With
End If
End With
Worksheet_Change_Exit:
Set rng = Nothing
End Sub