Excel - Formula validasi data

Isu

Saya memiliki spread sheet yang melacak kehadiran. Yang ingin saya lakukan adalah memberi tahu pengguna kapan saja 3 ATAU LEBIH BANYAK SEL DALAM URUTAN MENGANDUNG DATA YANG SAMA . misalnya. Jika seseorang memanggil sakit, S ditempatkan di sel, jika orang ini sakit Sen, sel, Rab, saya ingin memberi tahu pengguna. (3 hari berturut-turut dengan data yang sama). Jika orang itu sakit di Thur juga, saya ingin mengingatkan pengguna lagi.

Larutan

  • 1. Tekan ALT + F11 untuk membuka VBE
  • 2. Tekan CTRL + R untuk membuka Project Explorer
  • 3. Klik dua kali pada lembar di mana Anda ingin kotak pesan ini
  • 4. Tempel kode

 Private Sub Worksheet_Change (ByVal Target As Range) Dim vPos Sebagai Variant Dim iCol Sebagai Integer Dim CellValue Sebagai Variant If ((Target.Columns.Count = 1) Dan (Target.Rows.Count = 1)) Kemudian Jika Target = "" Lalu Keluar Sub Akhir Jika vPos = "" Application.EnableEvents = Salah Untuk Setiap Sel Dalam Target Jika UCase (Sel) "S" Kemudian Pergi Selanjutnya_Cell vPos = "" iCol = Sel.Column Jika iCol> = 3 Then If ((Cell = Cell .Offset (0, -2)) Dan (Cell.Offset (0, -1) = Cell)) Kemudian vPos = -1 End If End If If ((vPos = "") Dan (iCol> = 2) And ( iCol <Columns.Count)) Kemudian If ((Cell = Cell.Offset (0, -1)) Dan (Cell.Offset (0, 1) = Cell)) Kemudian vPos = 0 End If End If If ((vPos = "") Dan (iCol <Kolom.Count - 1)) Kemudian If ((Cell = Cell.Offset (0, 1)) Dan (Cell.Offset (0, 2) = Cell)) Kemudian vPos = 1 End If End If If (vPos "") Kemudian GoTo End_Sub End If Next_Cell: Next End_Sub: Application.EnableEvents = True If (vPos "") Kemudian MsgBox "Tiga berturut-turut" End If End Sub 

Jika Anda lansiran hanya diaktifkan untuk hari kerja (Senin hingga Jumat).

 Private Sub Worksheet_Change (ByVal Target As Range) Dim vPos Sebagai Variant Dim iCol Sebagai Integer Dim CellValue Sebagai Variant Dim iOffsetL2 Sebagai Integer Dim iOffsetL1 Sebagai Integer Dim iOffsetR1 Sebagai Integer Dim iOffset2 Sebagai Integer Dim CellL2 Sebagai Variant Dim CellL2 Sebagai Variant Dim CellL2 CellR1 As Variant Dim CellR2 As Variant If ((Target.Columns.Count = 1) Dan (Target.Rows.Count = 1)) Kemudian Jika Target = "" Lalu Keluar Sub End Jika vPos = "" 'Keluar Sub Pada Kesalahan GoTo Aplikasi End_Sub.EnableEvents = Salah Untuk Setiap Sel Di Target Cell0 = UCase (Cell.Value) 'Jika Cell0 "S" Lalu Pergi Selanjutnya_Cell vPos = "" iOffsetL2 = 0 iOffsetL1 = 0 iOffsetR1 = 0 iOffsetR2 = 0 iOffsetR2 = 0 iOffsetR2 = 0 iOffsetR2 = 0 iCoRset = (IsDate (Cells (1, iCol))) Lalu CellL2 = "Nilai Sampah" CellL1 = "Nilai Sampah" CellR1 = "Nilai Sampah" CellR2 = "Nilai Sampah" Pilih Kasus (Hari Kerja (Sel (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 Wadah Is = 5 iOffsetL2 = 0 iOffsetR1 = 0 iOffsetR1 = 2 iOffsetR2 = 2 Seleksi Pilih Akhir Jika Pada Kesalahan Kembali Lanjut CellL2 = Sel.Off2 (0, 2) )) .Nilai CellL1 = Cell.Offset (0, (-1 + iOffsetL1)) .Nilai CellR1 = Cell.Offset (0, (1 + iOffsetR1)). Nilai CellR2 = Cell.Offset (0, (2 + iOffsetR2) ). Nilai Pada Kesalahan GoTo End_Sub CellL2 = UCase (CellL2) CellL1 = UCase (CellL1) CellR1 = UCase (CellR1) CellR2 = UCase (CellR2) Jika (iCol + iOffsetL2> 2) Lalu '? ? X If ((CellL2 = Cell0) Dan (CellL1 = Cell0)) Kemudian vPos = -1 GoTo End_Sub End If End If If ((iCol + iOffsetL1> 0) Dan ((iCol - iOffsetR1) <Kolom. Jumlah)) Lalu ' ? X? If ((CellL1 = Cell0) Dan (Cell0 = CellR1)) Kemudian vPos = 0 GoTo End_Sub End If End If If (iCol <Columns.Count - 1) Lalu 'X? ? If ((Cell0 = CellR1) Dan (Cell0 = CellR2)) Kemudian vPos = 1 GoTo End_Sub End If End If Next_Cell: Next End_Sub: Application.EnableEvents = True If (vPos "") Kemudian MsgBox "Three in a row" End If End Sub 

Terima kasih kepada rizvisa1 untuk tip ini.

Artikel Sebelumnya Artikel Berikutnya

Tips