Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lRow As Long
Dim diff As Integer
lRow = Cells(Rows.Count, 2).End(xlUp).Row
If Selection.Count = 1 Then
If Not Intersect(Target, Range("E2:E" & lRow)) Is Nothing Then
UserForm3.Show
End If
If Not Intersect(Target, Range("F2:F" & lRow)) Is Nothing Then
UserForm3.Show
End If
End If
If IsUserFormLoaded("UserForm4") Then
diff = UserForm4.SpeciesID.Value - Cells(ActiveCell.Row, 2).Value
If diff = 0 Then
UserForm4.TextBox1.text = ActiveCell.text
Else
MsgBox " Selected field from wrong species"
End If
End If
End Sub
Function IsUserFormLoaded(ByVal UFName As String) As Boolean
Dim UForm As Object
IsUserFormLoaded = False
For Each UForm In VBA.UserForms
If UForm.Name = UFName Then
IsUserFormLoaded = True
Exit For
End If
Next
End Function