Private Sub CommandButton3_Click()'------------------------------------------------'
' Indsæt og gem vagt '
' Skriver værdierne på vagten i næste frie celle '
'------------------------------------------------'
'Opdaterer ikke skærm
Application.ScreenUpdating = False
'Advarsel ved manglende udfyldelse
If Me.TextBox2 = "" Then
MsgBox " Udfyld vagtnavn"
Me.TextBox2.SetFocus
Exit Sub
End If
If Me.TextBox3 = "" Then
MsgBox " Udfyld starttid"
Me.TextBox3.SetFocus
Exit Sub
End If
If Me.CheckBox1 = True And Me.TextBox4 = "" Then
MsgBox " Udfyld 1.del slut"
Me.TextBox4.SetFocus
Exit Sub
End If
If Me.CheckBox1 = True And Me.TextBox5 = "" Then
MsgBox " Udfyld 2.del start"
Me.TextBox5.SetFocus
Exit Sub
End If
If Me.TextBox6 = "" Then
MsgBox " Udfyld sluttid"
Me.TextBox6.SetFocus
Exit Sub
End If
If Me.TextBox7 = "" Then
MsgBox " Udfyld pausen" & vbNewLine & " Hvis ingen pause, skriv 0"
Me.TextBox7.SetFocus
Exit Sub
End If
If Me.TextBox8 = "" Then
MsgBox " Udfyld pausen" & vbNewLine & " Hvis ingen pause, skriv 0"
Me.TextBox8.SetFocus
Exit Sub
End If
If Me.TextBox9 = "" Then
MsgBox " Udfyld pausen" & vbNewLine & " Hvis ingen pause, skriv 0"
Me.TextBox9.SetFocus
Exit Sub
End If
If Me.TextBox10 = "" Then
MsgBox " Udfyld pausen" & vbNewLine & " Hvis ingen pause, skriv 0"
Me.TextBox10.SetFocus
Exit Sub
End If
If Me.TextBox11 = "" Then
MsgBox " Udfyld by."
Me.TextBox11.SetFocus
Exit Sub
End If
If Me.TextBox12 = "" Then
MsgBox " Udfyld kilometer."
Me.TextBox12.SetFocus
Exit Sub
End If
'nrf = next free row
Dim nfr As Range
'Finder den næste frie række
Set nrf = Worksheets("IndtastVagt").Range("A1000").End(xlUp).Offset(1, 0)
'Indsætter data fra textboxene
nrf.Offset(0, 0).Value = TextBox2.Value '................Vagt..............Kol 1
nrf.Offset(0, 1).Value = TextBox3.Value '................Start tid.........Kol 2
nrf.Offset(0, 2).Value = TextBox4.Value '................1. del slut.......Kol 3
nrf.Offset(0, 3).Value = TextBox5.Value '................2. del start......Kol 4
nrf.Offset(0, 4).Value = TextBox6.Value '................Slut tid..........Kol 5
'-----------------------------------------------'............Betalt pause......Kol 6
' 5-6-7 = Kol 6-7-8 skal kopieres nedad i fanen '............Selvbetalt pause..Kol 7
'-----------------------------------------------'............Eff timer.........Kol 8
nrf.Offset(0, 10).Value = TextBox7.Value '...............Pause 1 start.....Kol 11
nrf.Offset(0, 11).Value = TextBox8.Value '...............Pause 1 slut......Kol 12
nrf.Offset(0, 12).Value = TextBox9.Value '...............Pause 2 start.....Kol 13
nrf.Offset(0, 13).Value = TextBox10.Value '..............Pause 2 slut......Kol 14
nrf.Offset(0, 8).Value = TextBox11.Value '...............By................Kol 9
nrf.Offset(0, 9).Value = TextBox12.Value '...............Km................Kol 10
'--------------------------------------------------------------------------------
Sheets("IndtastVagt").Range("F1").Copy
nrf.Offset(0, 5).PasteSpecial xlPasteFormulas '............................Kol 6
Sheets("IndtastVagt").Range("G1").Copy
nrf.Offset(0, 6).PasteSpecial xlPasteFormulas '............................Kol 7
Sheets("IndtastVagt").Range("H1").Copy
nrf.Offset(0, 7).PasteSpecial xlPasteFormulas '............................Kol 8
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 14) = "X X ->" '.........................Start / Slut / Delt vagt
Rem nrf.Offset(0, 14).Font.Bold = True
Rem nrf.Offset(0, 14).Font.Color = vbRed '..................................Kol 15
Sheets("IndtastVagt").Range("P1").Copy
nrf.Offset(0, 15).PasteSpecial xlPasteFormulas '...........................Kol 16
Sheets("IndtastVagt").Range("Q1").Copy
nrf.Offset(0, 16).PasteSpecial xlPasteFormulas '...........................Kol 17
Sheets("IndtastVagt").Range("R1").Copy
nrf.Offset(0, 17).PasteSpecial xlPasteFormulas '...........................Kol 18
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 18) = "X X ->" '.......................Betalt / Selvbetalt pause
Rem nrf.Offset(0, 18).Font.Bold = True
Rem nrf.Offset(0, 18).Font.Color = vbRed '..................................Kol 19
Sheets("IndtastVagt").Range("T1").Copy
nrf.Offset(0, 19).PasteSpecial xlPasteFormulas '...........................Kol 20
Sheets("IndtastVagt").Range("U1").Copy
nrf.Offset(0, 20).PasteSpecial xlPasteFormulas '...........................Kol 21
Sheets("IndtastVagt").Range("V1").Copy
nrf.Offset(0, 21).PasteSpecial xlPasteFormulas '...........................Kol 22
Sheets("IndtastVagt").Range("W1").Copy
nrf.Offset(0, 22).PasteSpecial xlPasteFormulas '...........................Kol 23
Sheets("IndtastVagt").Range("X1").Copy
nrf.Offset(0, 23).PasteSpecial xlPasteFormulas '...........................Kol 24
Sheets("IndtastVagt").Range("Y1").Copy
nrf.Offset(0, 24).PasteSpecial xlPasteFormulas '...........................Kol 25
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 25) = "X X ->" '.................................Effektive timer
Rem nrf.Offset(0, 25).Font.Bold = True
Rem nrf.Offset(0, 25).Font.Color = vbRed '..................................Kol 26
Sheets("IndtastVagt").Range("AA1").Copy
nrf.Offset(0, 26).PasteSpecial xlPasteFormulas '...........................Kol 27
Sheets("IndtastVagt").Range("AB1").Copy
nrf.Offset(0, 27).PasteSpecial xlPasteFormulas '...........................Kol 28
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 28) = "X X ->" '.....................................Aftentillæg
Rem nrf.Offset(0, 28).Font.Bold = True
Rem nrf.Offset(0, 28).Font.Color = vbRed '..................................Kol 29
Sheets("IndtastVagt").Range("AD1").Copy
nrf.Offset(0, 29).PasteSpecial xlPasteFormulas '...........................Kol 30
Sheets("IndtastVagt").Range("AE1").Copy
nrf.Offset(0, 30).PasteSpecial xlPasteFormulas '...........................Kol 31
Sheets("IndtastVagt").Range("AF1").Copy
nrf.Offset(0, 31).PasteSpecial xlPasteFormulas '...........................Kol 32
Sheets("IndtastVagt").Range("AG1").Copy
nrf.Offset(0, 32).PasteSpecial xlPasteFormulas '...........................Kol 33
Sheets("IndtastVagt").Range("AH1").Copy
nrf.Offset(0, 33).PasteSpecial xlPasteFormulas '...........................Kol 34
Sheets("IndtastVagt").Range("AI1").Copy
nrf.Offset(0, 34).PasteSpecial xlPasteFormulas '...........................Kol 35
Sheets("IndtastVagt").Range("AJ1").Copy
nrf.Offset(0, 35).PasteSpecial xlPasteFormulas '...........................Kol 36
Sheets("IndtastVagt").Range("AK1").Copy
nrf.Offset(0, 36).PasteSpecial xlPasteFormulas '...........................Kol 37
Sheets("IndtastVagt").Range("AL1").Copy
nrf.Offset(0, 37).PasteSpecial xlPasteFormulas '...........................Kol 38
Sheets("IndtastVagt").Range("AM1").Copy
nrf.Offset(0, 38).PasteSpecial xlPasteFormulas '...........................Kol 39
Sheets("IndtastVagt").Range("AN1").Copy
nrf.Offset(0, 39).PasteSpecial xlPasteFormulas '...........................Kol 40
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 40) = "X X ->" '.......................................Nattillæg
Rem nrf.Offset(0, 40).Font.Bold = True
Rem nrf.Offset(0, 40).Font.Color = vbRed '..................................Kol 41
Sheets("IndtastVagt").Range("AP1").Copy
nrf.Offset(0, 41).PasteSpecial xlPasteFormulas '...........................Kol 42
Sheets("IndtastVagt").Range("AQ1").Copy
nrf.Offset(0, 42).PasteSpecial xlPasteFormulas '...........................Kol 43
Sheets("IndtastVagt").Range("AR1").Copy
nrf.Offset(0, 43).PasteSpecial xlPasteFormulas '...........................Kol 44
Sheets("IndtastVagt").Range("AS1").Copy
nrf.Offset(0, 44).PasteSpecial xlPasteFormulas '...........................Kol 45
Sheets("IndtastVagt").Range("AT1").Copy
nrf.Offset(0, 45).PasteSpecial xlPasteFormulas '...........................Kol 46
Sheets("IndtastVagt").Range("AU1").Copy
nrf.Offset(0, 46).PasteSpecial xlPasteFormulas '...........................Kol 47
Sheets("IndtastVagt").Range("AV1").Copy
nrf.Offset(0, 47).PasteSpecial xlPasteFormulas '...........................Kol 48
Sheets("IndtastVagt").Range("AW1").Copy
nrf.Offset(0, 48).PasteSpecial xlPasteFormulas '...........................Kol 49
Sheets("IndtastVagt").Range("AX1").Copy
nrf.Offset(0, 49).PasteSpecial xlPasteFormulas '...........................Kol 50
Sheets("IndtastVagt").Range("AY1").Copy
nrf.Offset(0, 50).PasteSpecial xlPasteFormulas '...........................Kol 51
Sheets("IndtastVagt").Range("AZ1").Copy
nrf.Offset(0, 51).PasteSpecial xlPasteFormulas '...........................Kol 52
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 52) = "X X ->" '...................................Lørdagstillæg
Rem nrf.Offset(0, 52).Font.Bold = True
Rem nrf.Offset(0, 52).Font.Color = vbRed '..................................Kol 53
Sheets("IndtastVagt").Range("BB1").Copy
nrf.Offset(0, 53).PasteSpecial xlPasteFormulas '...........................Kol 54
Sheets("IndtastVagt").Range("BC1").Copy
nrf.Offset(0, 54).PasteSpecial xlPasteFormulas '...........................Kol 55
Sheets("IndtastVagt").Range("BD1").Copy
nrf.Offset(0, 55).PasteSpecial xlPasteFormulas '...........................Kol 56
Sheets("IndtastVagt").Range("BE1").Copy
nrf.Offset(0, 56).PasteSpecial xlPasteFormulas '...........................Kol 57
Sheets("IndtastVagt").Range("BF1").Copy
nrf.Offset(0, 57).PasteSpecial xlPasteFormulas '...........................Kol 58
Sheets("IndtastVagt").Range("BG1").Copy
nrf.Offset(0, 58).PasteSpecial xlPasteFormulas '...........................Kol 59
Sheets("IndtastVagt").Range("BH1").Copy
nrf.Offset(0, 59).PasteSpecial xlPasteFormulas '...........................Kol 60
Sheets("IndtastVagt").Range("BI1").Copy
nrf.Offset(0, 60).PasteSpecial xlPasteFormulas '...........................Kol 61
Sheets("IndtastVagt").Range("BJ1").Copy
nrf.Offset(0, 61).PasteSpecial xlPasteFormulas '...........................Kol 62
Sheets("IndtastVagt").Range("BK1").Copy
nrf.Offset(0, 62).PasteSpecial xlPasteFormulas '...........................Kol 63
Sheets("IndtastVagt").Range("BL1").Copy
nrf.Offset(0, 63).PasteSpecial xlPasteFormulas '...........................Kol 64
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 64) = "X X ->" '....................................Grundlovsdag
Rem nrf.Offset(0, 64).Font.Bold = True
Rem nrf.Offset(0, 64).Font.Color = vbRed '..................................Kol 65
Sheets("IndtastVagt").Range("BN1").Copy
nrf.Offset(0, 65).PasteSpecial xlPasteFormulas '...........................Kol 66
Sheets("IndtastVagt").Range("BO1").Copy
nrf.Offset(0, 66).PasteSpecial xlPasteFormulas '...........................Kol 67
Sheets("IndtastVagt").Range("BP1").Copy
nrf.Offset(0, 67).PasteSpecial xlPasteFormulas '...........................Kol 68
Sheets("IndtastVagt").Range("BQ1").Copy
nrf.Offset(0, 68).PasteSpecial xlPasteFormulas '...........................Kol 69
Sheets("IndtastVagt").Range("BR1").Copy
nrf.Offset(0, 69).PasteSpecial xlPasteFormulas '...........................Kol 70
Sheets("IndtastVagt").Range("BS1").Copy
nrf.Offset(0, 70).PasteSpecial xlPasteFormulas '...........................Kol 71
Sheets("IndtastVagt").Range("BT1").Copy
nrf.Offset(0, 71).PasteSpecial xlPasteFormulas '...........................Kol 72
Sheets("IndtastVagt").Range("BU1").Copy
nrf.Offset(0, 72).PasteSpecial xlPasteFormulas '...........................Kol 73
Sheets("IndtastVagt").Range("BV1").Copy
nrf.Offset(0, 73).PasteSpecial xlPasteFormulas '...........................Kol 74
Sheets("IndtastVagt").Range("BW1").Copy
nrf.Offset(0, 74).PasteSpecial xlPasteFormulas '...........................Kol 75
Sheets("IndtastVagt").Range("BX1").Copy
nrf.Offset(0, 75).PasteSpecial xlPasteFormulas '...........................Kol 76
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 76) = "X X ->" '....................................Start før SH
Rem nrf.Offset(0, 76).Font.Bold = True
Rem nrf.Offset(0, 76).Font.Color = vbRed '..................................Kol 77
Sheets("IndtastVagt").Range("BZ1").Copy
nrf.Offset(0, 77).PasteSpecial xlPasteFormulas '...........................Kol 78
Sheets("IndtastVagt").Range("CA1").Copy
nrf.Offset(0, 78).PasteSpecial xlPasteFormulas '...........................Kol 79
Sheets("IndtastVagt").Range("CB1").Copy
nrf.Offset(0, 79).PasteSpecial xlPasteFormulas '...........................Kol 80
Sheets("IndtastVagt").Range("CC1").Copy
nrf.Offset(0, 80).PasteSpecial xlPasteFormulas '...........................Kol 81
Sheets("IndtastVagt").Range("CD1").Copy
nrf.Offset(0, 81).PasteSpecial xlPasteFormulas '...........................Kol 82
Sheets("IndtastVagt").Range("CE1").Copy
nrf.Offset(0, 82).PasteSpecial xlPasteFormulas '...........................Kol 83
Sheets("IndtastVagt").Range("CF1").Copy
nrf.Offset(0, 83).PasteSpecial xlPasteFormulas '...........................Kol 84
Sheets("IndtastVagt").Range("CG1").Copy
nrf.Offset(0, 84).PasteSpecial xlPasteFormulas '...........................Kol 85
Sheets("IndtastVagt").Range("CH1").Copy
nrf.Offset(0, 85).PasteSpecial xlPasteFormulas '...........................Kol 86
Sheets("IndtastVagt").Range("CI1").Copy
nrf.Offset(0, 86).PasteSpecial xlPasteFormulas '...........................Kol 87
Sheets("IndtastVagt").Range("CJ1").Copy
nrf.Offset(0, 87).PasteSpecial xlPasteFormulas '...........................Kol 88
'-------------------------------------------------------------------------------
Rem nrf.Offset(0, 88) = "X X ->" '.......................................SH tillæg
Rem nrf.Offset(0, 88).Font.Bold = True
Rem nrf.Offset(0, 88).Font.Color = vbRed '..................................Kol 89
Sheets("IndtastVagt").Range("CL1").Copy
nrf.Offset(0, 89).PasteSpecial xlPasteFormulas '...........................Kol 90
Rem nrf.Offset(0, 90) = "X X ->" '.........................SH tillæg - Bruges ikke
Rem nrf.Offset(0, 90).Font.Bold = True
Rem nrf.Offset(0, 90).Font.Color = vbRed '..................................Kol 91
Sheets("IndtastVagt").Range("CN1").Copy
nrf.Offset(0, 91).PasteSpecial xlPasteFormulas '...........................Kol 92
Sheets("IndtastVagt").Range("CO1").Copy
nrf.Offset(0, 92).PasteSpecial xlPasteFormulas '...........................Kol 93
Rem nrf.Offset(0, 93) = "X X ->" '.........................SH tillæg - Bruges ikke
Rem nrf.Offset(0, 93).Font.Bold = True
Rem nrf.Offset(0, 93).Font.Color = vbRed '..................................Kol 94
Sheets("IndtastVagt").Range("CQ1").Copy
nrf.Offset(0, 94).PasteSpecial xlPasteFormulas '...........................Kol 95
Sheets("IndtastVagt").Range("CR1").Copy
nrf.Offset(0, 95).PasteSpecial xlPasteFormulas '...........................Kol 96
Sheets("IndtastVagt").Range("CS1").Copy
nrf.Offset(0, 96).PasteSpecial xlPasteFormulas '...........................Kol 97
Sheets("IndtastVagt").Range("CT1").Copy
nrf.Offset(0, 97).PasteSpecial xlPasteFormulas '...........................Kol 98
Sheets("IndtastVagt").Range("CU1").Copy
nrf.Offset(0, 98).PasteSpecial xlPasteFormulas '...........................Kol 99
Sheets("IndtastVagt").Range("CV1").Copy
nrf.Offset(0, 99).PasteSpecial xlPasteFormulas '..........................Kol 100
'--------------------------------------------------------------------------------
Rem nrf.Offset(0, 100) = "X X ->" '........................................Diverse
Rem nrf.Offset(0, 100).Font.Bold = True
Rem nrf.Offset(0, 100).Font.Color = vbRed '................................Kol 101
Sheets("IndtastVagt").Range("CX1").Copy
nrf.Offset(0, 101).PasteSpecial xlPasteFormulas '.........................Kol 102
Sheets("IndtastVagt").Range("CY1").Copy
nrf.Offset(0, 102).PasteSpecial xlPasteFormulas '.........................Kol 103
Sheets("IndtastVagt").Range("CZ1").Copy
nrf.Offset(0, 103).PasteSpecial xlPasteFormulas '.........................Kol 104
Sheets("IndtastVagt").Range("DA1").Copy
nrf.Offset(0, 104).PasteSpecial xlPasteFormulas '.........................Kol 105
Sheets("IndtastVagt").Range("DB1").Copy
nrf.Offset(0, 105).PasteSpecial xlPasteFormulas '.........................Kol 106
'---------------------------------------------------------------------------------
Rem nrf.Offset(0, 106) = "X X ->" '........................................Overtid
Rem nrf.Offset(0, 106).Font.Bold = True
Rem nrf.Offset(0, 106).Font.Color = vbRed '................................Kol 107
Sheets("IndtastVagt").Range("DD1").Copy
nrf.Offset(0, 107).PasteSpecial xlPasteFormulas '.........................Kol 108
Sheets("IndtastVagt").Range("DE1").Copy
nrf.Offset(0, 108).PasteSpecial xlPasteFormulas '.........................Kol 109
Sheets("IndtastVagt").Range("DF1").Copy
nrf.Offset(0, 109).PasteSpecial xlPasteFormulas '.........................Kol 110
Sheets("IndtastVagt").Range("DG1").Copy
nrf.Offset(0, 110).PasteSpecial xlPasteFormulas '.........................Kol 111
'---------------------------------------------------------------------------------
'Sortere stigende efter vagt
Sheets("IndtastVagt").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("IndtastVagt").Sort
.SetRange Range("A1:DG1000")
.Header = xlYes '***** xlNo ny 29-07-2017
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Sletter textboxene
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
TextBox11 = ""
TextBox12 = ""
'Opdaterer listen i userform
Dim rk As Long
Dim sv As Long
rk = Sheets("IndtastVagt").Cells(1000, "A").End(xlUp).Row
If rk < 2 Then Exit Sub
Me.ListBox1.List = Sheets("IndtastVagt").Range("A2:N" & rk).Value
'Formater tal til tid
For j = ListBox1.ListCount - 1 To 0 Step -1 ' Formater tal til tid
Me.ListBox1.List(j, 1) = Format(Me.ListBox1.List(j, 1), "hh:mm") ' Kolonne 2 - Vagt Start
Me.ListBox1.List(j, 2) = Format(Me.ListBox1.List(j, 2), "hh:mm") ' Kolonne 3 - 1. del slut
Me.ListBox1.List(j, 3) = Format(Me.ListBox1.List(j, 3), "hh:mm") ' Kolonne 4 - 2. del start
Me.ListBox1.List(j, 4) = Format(Me.ListBox1.List(j, 4), "hh:mm") ' Kolonne 5 - Vagt Slut
Me.ListBox1.List(j, 5) = Format(Me.ListBox1.List(j, 5), "hh:mm") ' Kolonne 6 - Betalt pause
Me.ListBox1.List(j, 6) = Format(Me.ListBox1.List(j, 6), "hh:mm") ' Kolonne 7 - Selvb. pause
Me.ListBox1.List(j, 7) = Format(Me.ListBox1.List(j, 7), "hh:mm") ' Kolonne 8 - Eff. timer
Me.ListBox1.List(j, 10) = Format(Me.ListBox1.List(j, 10), "hh:mm") ' Kolonne 11 - Pause 1 start
Me.ListBox1.List(j, 11) = Format(Me.ListBox1.List(j, 11), "hh:mm") ' Kolonne 12 - Pause 1 slut
Me.ListBox1.List(j, 12) = Format(Me.ListBox1.List(j, 12), "hh:mm") ' Kolonne 13 - Pause 2 start
Me.ListBox1.List(j, 13) = Format(Me.ListBox1.List(j, 13), "hh:mm") ' Kolonne 14 - Pause 2 slut
Next
'Hopper til vagt textboxen, klar til ny indtastning
Me.TextBox2.SetFocus
'Nulstiller markering af kopieringen
Application.CutCopyMode = False
End Sub