diff --git a/src/module/Common_Functions.bas b/src/module/Common_Functions.bas index f952e66..f49fbf7 100644 --- a/src/module/Common_Functions.bas +++ b/src/module/Common_Functions.bas @@ -428,3 +428,32 @@ Function Check12(ByVal ws As Worksheet, ByVal rowNum As Long, ByVal colNum As Lo End If Check12 = True End Function + +Function CheckDuplicate(ByVal ws As Worksheet, ByVal rowNum As Long, ByVal colNum As Long, ByVal errorCol As String) As Boolean + Dim checkValue As String: checkValue = Trim(ws.Cells(rowNum, colNum).Value) + Dim letter As String: letter = ColLetter(colNum) + Dim i As Long + + For i = 7 To rowNum - 1 + If Trim(ws.Cells(i, colNum).Value) = checkValue Then + ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E010", letter & rowNum, checkValue) + ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0) + CheckDuplicate = False + Exit Function + End If + Next i + + CheckDuplicate = True +End Function + +Function CheckNumber(ByVal ws As Worksheet, ByVal rowNum As Long, ByVal colNum As Long, ByVal varcharLength As Long, ByVal errorCol As String) + Dim checkValue As String: checkValue = Trim(ws.Cells(rowNum, colNum).Value) + If Len(checkValue) > varcharLength Then + Dim letter As String: letter = ColLetter(colNum) + ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E011", letter & rowNum) + ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0) + CheckVarcharOver = False + Exit Function + End If + CheckVarcharOver = True +End Function diff --git a/src/sheet/M2.cls b/src/sheet/M2.cls index 7d6960c..7825bfb 100644 --- a/src/sheet/M2.cls +++ b/src/sheet/M2.cls @@ -21,7 +21,7 @@ Private Sub Worksheet_Change(ByVal Target As Range) End If End Sub -Private Sub FillFromM1(ByVal rowNum As Long, Optional ByVal setG As Boolean = True) +Private Sub FillFromM1(ByVal rowNum As Long) Set ws = Me Dim m1Cache As Object: Set m1Cache = GetM1Cache() @@ -36,15 +36,18 @@ Private Sub FillFromM1(ByVal rowNum As Long, Optional ByVal setG As Boolean = Tr ' Check C column in the cache If Not m1Cache.Exists(cValue) Then - ws.Cells(rowNum, ERROR_COL).Value = "C column does not exist in M1." - ws.Range("C" & rowNum).Interior.Color = RGB(255, 0, 0) + ws.Cells(rowNum, 4).Value = "" + ws.Cells(rowNum, 5).Value = "" + ws.Cells(rowNum, 6).Value = "" + ws.Cells(rowNum, 7).Value = "" + ws.Cells(rowNum, 8).Value = "" Exit Sub End If Dim cacheVal As Variant: cacheVal = m1Cache(cValue) ' D column = cache[1]: cache[2] - ws.Cells(rowNum, 4).Value = Trim(cacheVal(1)) & ": " & Trim(cacheVal(2)) + ws.Cells(rowNum, 4).Value = Trim(cacheVal(1)) & ":" & Trim(cacheVal(2)) ' E column = cache[3] ws.Cells(rowNum, 5).Value = Trim(cacheVal(3)) ' F column = cache[4] @@ -76,19 +79,23 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As ' Check C column in the cache Dim m1Cache As Object: Set m1Cache = GetM1Cache() - Dim cValue As String: cValue = Trim(ws.Range("C" & rowNum).Value) - If cValue <> "" AND Not m1Cache.Exists(cValue) Then - ws.Cells(rowNum, errorCol).Value = "C column does not exist in M1." + ' C column check + checkResult = CheckRequired(ws, rowNum, 3, errorCol) + If checkResult = False Then Exit Sub + + Dim cValue As String: cValue = Trim(ws.Range("C" & rowNum).Value) + If Not m1Cache.Exists(cValue) Then + ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E004", "C" & rowNum) ws.Range("C" & rowNum).Interior.Color = RGB(255, 0, 0) Exit Sub End If ' Check column required Dim colLetter As Variant - For Each colLetter In Array("C", "I", "J", "K") + For Each colLetter In Array("I", "J", "K") If Trim(ws.Range(colLetter & rowNum).Value) = "" Then - ws.Cells(rowNum, errorCol).Value = colLetter & " column is required" + ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E002", colLetter & rowNum) ws.Range(colLetter & rowNum).Interior.Color = RGB(255, 0, 0) Exit Sub End If @@ -100,19 +107,24 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As For Each col In numericCols Dim val As String: val = Trim(ws.Range(col & rowNum).Value & "") If val <> "" And Not IsNumeric(val) Then - ws.Cells(rowNum, errorCol).Value = col & " column must be numeric" + ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E011", col & rowNum) ws.Range(col & rowNum).Interior.Color = RGB(255, 0, 0) Exit Sub End If Next col ' Check I column in the kenshuKbn - Dim kenshuKbn As Variant: kenshuKbn = Array("1", "2", "3") - Dim iValue As String: iValue = Trim(ws.Range("I" & rowNum).Value) - If UBound(Filter(kenshuKbn, iValue)) = -1 Then - ws.Cells(rowNum, errorCol).Value = "I column (kenshuKbn) must be 1, 2, or 3" + Dim kenshuList As Object: Set kenshuList = GetKenshuList() + Dim kenshuKbn As String: kenshuKbn = Trim(ws.Range("I" & rowNum).Value) + If Not kenshuList.Exists(kenshuKbn) Then + ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E012", "I" & rowNum) ws.Range("I" & rowNum).Interior.Color = RGB(255, 0, 0) Exit Sub End If + ws.Cells(rowNum, errorCol).ClearContents + +End Sub + +Sub ImportCSVAndTriggerChange(ws As Worksheet) End Sub diff --git a/src/sheet/Z1.cls b/src/sheet/Z1.cls index 0e44d15..8ba642f 100644 --- a/src/sheet/Z1.cls +++ b/src/sheet/Z1.cls @@ -30,6 +30,9 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As checkResult = CheckAlphanumeric(ws, rowNum, 3, 3, errorCol) If checkResult = False Then Exit Sub + checkResult = CheckDuplicate(ws, rowNum, 3, errorCol) + If checkResult = False Then Exit Sub + ' D column check checkResult = CheckRequired(ws, rowNum, 4, errorCol) If checkResult = False Then Exit Sub diff --git a/src/sheet/Z2.cls b/src/sheet/Z2.cls index a3ffab0..e09f2a0 100644 --- a/src/sheet/Z2.cls +++ b/src/sheet/Z2.cls @@ -27,6 +27,9 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As checkResult = CheckAlphanumeric(ws, rowNum, 3, 1, errorCol) If checkResult = False Then Exit Sub + + checkResult = CheckDuplicate(ws, rowNum, 3, errorCol) + If checkResult = False Then Exit Sub ' D column check checkResult = CheckRequired(ws, rowNum, 4, errorCol) diff --git a/src/sheet/Z3.cls b/src/sheet/Z3.cls index e58699f..2e7abee 100644 --- a/src/sheet/Z3.cls +++ b/src/sheet/Z3.cls @@ -26,6 +26,9 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As checkResult = CheckAlphanumeric(ws, rowNum, 3, 2, errorCol) If checkResult = False Then Exit Sub + + checkResult = CheckDuplicate(ws, rowNum, 3, errorCol) + If checkResult = False Then Exit Sub ' D column check checkResult = CheckRequired(ws, rowNum, 4, errorCol) diff --git a/src/sheet/Z4.cls b/src/sheet/Z4.cls index 16b122b..7510867 100644 --- a/src/sheet/Z4.cls +++ b/src/sheet/Z4.cls @@ -26,6 +26,9 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As checkResult = CheckAlphanumeric(ws, rowNum, 3, 2, errorCol) If checkResult = False Then Exit Sub + + checkResult = CheckDuplicate(ws, rowNum, 3, errorCol) + If checkResult = False Then Exit Sub ' D column check checkResult = CheckRequired(ws, rowNum, 4, errorCol) diff --git a/通勤手当テンプレート_案.xlsm b/通勤手当テンプレート_案.xlsm index 0ce4a22..702c33f 100644 Binary files a/通勤手当テンプレート_案.xlsm and b/通勤手当テンプレート_案.xlsm differ