edit M2
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,8 +36,11 @@ 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -28,6 +28,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)
|
||||
If checkResult = False Then Exit Sub
|
||||
|
||||
@@ -27,6 +27,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)
|
||||
If checkResult = False Then Exit Sub
|
||||
|
||||
@@ -27,6 +27,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)
|
||||
If checkResult = False Then Exit Sub
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user