For the worksheet
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("D:D,F:F,H:H,J:J")) Is Nothing Then
UserForm1.Show
End If
End Sub
Button on the form
Private Sub CommandButton1_Click()
Dim mr As Range, r As Long, mhours As Double
mhours = Replace(TextBox2, ".", ",") ' could be you dont need this line, depending on your decimal settings
With Range("N:N")
Set mr = .Find(Val(TextBox1))
If Not mr Is Nothing Then
r = mr.Row
Else
Set mr = .Find("", after:=.Cells(3))
r = mr.Row
End If
Cells(r, "N") = TextBox1.Value
Cells(r, "O") = Cells(r, "O").Value + mhours
Cells(ActiveCell.Row, ActiveCell.Column).Resize(, 2) = Array(Val(TextBox1), mhours)
End With
lr = Range("N" & Rows.Count).End(xlUp).Row - 2
Range("N3", "O" & lr).Sort key1:=[N3], Header:=xlYes
Unload Me
End Sub
Kind regards
Leo
Bookmarks