Excel - Data-validatieformule

Kwestie

Ik heb een spreadsheet waarin de aanwezigheid wordt bijgehouden. Wat ik wil doen is de gebruiker waarschuwen wanneer 3 OF MEER VOLGENDE CELLEN DEZELFDE GEGEVENS BEVATTEN . bv. Als iemand zich ziek meldt, wordt een S in de cel geplaatst, als deze persoon ziek is maandag, dinsdag, woensdag, wil ik de gebruiker waarschuwen. (3 dagen achtereen met dezelfde gegevens). Als de persoon ook ziek is op Thur, wil ik de gebruiker opnieuw waarschuwen.

Oplossing

  • 1. Druk op ALT + F11 om VBE te openen
  • 2. Druk op CTRL + R om Projectverkenner te openen
  • 3. Dubbelklik op het blad waarin u dit bericht wilt plaatsen
  • 4. Plak de code

 Particulier Subwerkblad_Wijzigen (ByVal-doel als bereik) Dim vPos als Variant Dim iCol As Integer Dim CellValue As Variant If ((Target.Columns.Count = 1) En (Target.Rows.Count = 1)) Then If Target = "" Then Sub-einde afsluiten Als vPos = "" Application.EnableEvents = False voor elke cel in doel Als UCase (cel) "S" dan GoTo Next_Cell vPos = "" iCol = Cell.Column If iCol> = 3 Then If ((Cell = Cell .Offset (0, -2)) En (Cell.Offset (0, -1) = Cell)) Then vPos = -1 End If End If If ((vPos = "") And (iCol> = 2) And ( iCol <Columns.Count)) Then If ((Cell = Cell.Offset (0, -1)) And (Cell.Offset (0, 1) = Cell)) Then vPos = 0 End If End If If ((vPos = "") En (iCol <Columns.Count - 1)) Then If ((Cell = Cell.Offset (0, 1)) And (Cell.Offset (0, 2) = Cell)) Then vPos = 1 End If End If If (vPos "") Then GoTo End_Sub End If Next_Cell: Next End_Sub: Application.EnableEvents = True If (vPos "") Then MsgBox "Three in a row" End If End Sub 

Als u de waarschuwingen alleen wilt inschakelen voor weekdagen (van maandag tot vrijdag).

 Particulier Subwerkblad_Wijzigen (ByVal-doel als bereik) Dim vPos Als Variant Dim iCol As Geheel getal Dim CellValue Als Variant Dim iOffsetL2 Als geheelengedeelte Dim iOffsetL1 Als geheel getal Dim iOffset R1 Als geheel getal Dim iOffset2 Als geheel getal Dim CellL2 als variant Dim CellL1 Als variant Dim-cel0 Als variant Dim CellR1 As Variant Dim CellR2 As Variant If ((Target.Columns.Count = 1) En (Target.Rows.Count = 1)) Then If Target = "" Then Exit Sub End If vPos = "" 'Exit Sub On Error GoTo End_Sub Application.EnableEvents = False voor elke cel in doelcel0 = UCase (Cell.Value) 'If Cell0' S 'Then GoTo Next_Cell vPos = "" iOffsetL2 = 0 iOffsetL1 = 0 iOffsetR1 = 0 iOffsetR2 = 0 iCol = Cell.Column If (IsDate (cellen (1, iCol))) Vervolgens CellL2 = "Garbage-waarde" CellL1 = "Garbage-waarde" CellR1 = "Garbage-waarde" CellR2 = "Garbage-waarde" Case selecteren (weekdag (cellen (1, iCol), vbMonday) ) Case Is = 1 iOffsetL2 = -2 iOffsetL1 = -2 iOffsetR1 = 0 iOffsetR2 = 0 Case Is = 2 iOffsetL2 = -2 iOffsetL1 = 0 iOffsetR1 = 0 iOffsetR2 = 0 Case Is = 4 iOffsetL2 = 0 iOffsetL1 = 0 iOffsetR1 = 0 iOffsetR2 = 2 Case Is = 5 iOffsetL2 = 0 iOffsetL1 = 0 iOffsetR1 = 2 iOffsetR2 = 2 End Selecteer End If On Error Hervat volgende CellL2 = Cell.Offset (0, (-2 + iOffsetL2 )). Waarde CellL1 = Cell.Offset (0, (-1 + iOffsetL1)). Waarde CellR1 = Cell.Offset (0, (1 + iOffsetR1)). Waarde CellR2 = Cell.Offset (0, (2 + iOffsetR2) ). Waarde op fout GoTo End_Sub CellL2 = UCase (CellL2) CellL1 = UCase (CellL1) CellR1 = UCase (CellR1) CellR2 = UCase (CellR2) If (iCol + iOffsetL2> 2) Then '? ? X If ((CellL2 = Cell0) En (CellL1 = Cell0)) Then vPos = -1 GoTo End_Sub End If End If If ((iCol + iOffsetL1> 0) En ((iCol - iOffsetR1) <Columns.Count)) Then ' ? X? If ((CellL1 = Cell0) And (Cell0 = CellR1)) Then vPos = 0 GoTo End_Sub End If End If If (iCol <Columns.Count - 1) Then 'X? ? If ((Cell0 = CellR1) En (Cell0 = CellR2)) Then vPos = 1 GoTo End_Sub End If End If Next_Cell: Next End_Sub: Application.EnableEvents = True If (vPos "") Then MsgBox "Three in a row" End If End Sub 

Dank aan rizvisa1 voor deze tip.

Vorige Artikel Volgende Artikel

Top Tips