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
|
End If
|
||||||
Check12 = True
|
Check12 = True
|
||||||
End Function
|
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 If
|
||||||
End Sub
|
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
|
Set ws = Me
|
||||||
|
|
||||||
Dim m1Cache As Object: Set m1Cache = GetM1Cache()
|
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
|
' Check C column in the cache
|
||||||
If Not m1Cache.Exists(cValue) Then
|
If Not m1Cache.Exists(cValue) Then
|
||||||
ws.Cells(rowNum, ERROR_COL).Value = "C column does not exist in M1."
|
ws.Cells(rowNum, 4).Value = ""
|
||||||
ws.Range("C" & rowNum).Interior.Color = RGB(255, 0, 0)
|
ws.Cells(rowNum, 5).Value = ""
|
||||||
|
ws.Cells(rowNum, 6).Value = ""
|
||||||
|
ws.Cells(rowNum, 7).Value = ""
|
||||||
|
ws.Cells(rowNum, 8).Value = ""
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Dim cacheVal As Variant: cacheVal = m1Cache(cValue)
|
Dim cacheVal As Variant: cacheVal = m1Cache(cValue)
|
||||||
|
|
||||||
' D column = cache[1]: cache[2]
|
' 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]
|
' E column = cache[3]
|
||||||
ws.Cells(rowNum, 5).Value = Trim(cacheVal(3))
|
ws.Cells(rowNum, 5).Value = Trim(cacheVal(3))
|
||||||
' F column = cache[4]
|
' 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
|
' Check C column in the cache
|
||||||
Dim m1Cache As Object: Set m1Cache = GetM1Cache()
|
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
|
' C column check
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column does not exist in M1."
|
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)
|
ws.Range("C" & rowNum).Interior.Color = RGB(255, 0, 0)
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' Check column required
|
' Check column required
|
||||||
Dim colLetter As Variant
|
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
|
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)
|
ws.Range(colLetter & rowNum).Interior.Color = RGB(255, 0, 0)
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
@@ -100,19 +107,24 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
|||||||
For Each col In numericCols
|
For Each col In numericCols
|
||||||
Dim val As String: val = Trim(ws.Range(col & rowNum).Value & "")
|
Dim val As String: val = Trim(ws.Range(col & rowNum).Value & "")
|
||||||
If val <> "" And Not IsNumeric(val) Then
|
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)
|
ws.Range(col & rowNum).Interior.Color = RGB(255, 0, 0)
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
Next col
|
Next col
|
||||||
|
|
||||||
' Check I column in the kenshuKbn
|
' Check I column in the kenshuKbn
|
||||||
Dim kenshuKbn As Variant: kenshuKbn = Array("1", "2", "3")
|
Dim kenshuList As Object: Set kenshuList = GetKenshuList()
|
||||||
Dim iValue As String: iValue = Trim(ws.Range("I" & rowNum).Value)
|
Dim kenshuKbn As String: kenshuKbn = Trim(ws.Range("I" & rowNum).Value)
|
||||||
If UBound(Filter(kenshuKbn, iValue)) = -1 Then
|
If Not kenshuList.Exists(kenshuKbn) Then
|
||||||
ws.Cells(rowNum, errorCol).Value = "I column (kenshuKbn) must be 1, 2, or 3"
|
ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E012", "I" & rowNum)
|
||||||
ws.Range("I" & rowNum).Interior.Color = RGB(255, 0, 0)
|
ws.Range("I" & rowNum).Interior.Color = RGB(255, 0, 0)
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
ws.Cells(rowNum, errorCol).ClearContents
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub ImportCSVAndTriggerChange(ws As Worksheet)
|
||||||
End Sub
|
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)
|
checkResult = CheckAlphanumeric(ws, rowNum, 3, 3, errorCol)
|
||||||
If checkResult = False Then Exit Sub
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckDuplicate(ws, rowNum, 3, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
' D column check
|
' D column check
|
||||||
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
||||||
If checkResult = False Then Exit Sub
|
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, 1, errorCol)
|
checkResult = CheckAlphanumeric(ws, rowNum, 3, 1, errorCol)
|
||||||
If checkResult = False Then Exit Sub
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckDuplicate(ws, rowNum, 3, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
' D column check
|
' D column check
|
||||||
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
|||||||
|
|
||||||
checkResult = CheckAlphanumeric(ws, rowNum, 3, 2, errorCol)
|
checkResult = CheckAlphanumeric(ws, rowNum, 3, 2, errorCol)
|
||||||
If checkResult = False Then Exit Sub
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckDuplicate(ws, rowNum, 3, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
' D column check
|
' D column check
|
||||||
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
|||||||
|
|
||||||
checkResult = CheckAlphanumeric(ws, rowNum, 3, 2, errorCol)
|
checkResult = CheckAlphanumeric(ws, rowNum, 3, 2, errorCol)
|
||||||
If checkResult = False Then Exit Sub
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckDuplicate(ws, rowNum, 3, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
' D column check
|
' D column check
|
||||||
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user