refactor error
This commit is contained in:
@@ -5,7 +5,7 @@ Sub ImportModulesAndSheets_Safe()
|
|||||||
Dim fso As Object
|
Dim fso As Object
|
||||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||||
|
|
||||||
Const PROJECT_PATH As String = "E:\AI\project\updsv7\vba\"
|
Const PROJECT_PATH As String = "D:\Project\upds7\vba\"
|
||||||
Const MODULE_PATH As String = PROJECT_PATH & "src\module"
|
Const MODULE_PATH As String = PROJECT_PATH & "src\module"
|
||||||
Const SHEET_PATH As String = PROJECT_PATH & "src\sheet"
|
Const SHEET_PATH As String = PROJECT_PATH & "src\sheet"
|
||||||
|
|
||||||
|
|||||||
@@ -284,7 +284,6 @@ private Function RunValidationSilent(ws As Worksheet, Optional ByRef errorCountO
|
|||||||
Dim errorMessage As String : errorMessage = Trim(ws.Cells(r, errorCol).Value)
|
Dim errorMessage As String : errorMessage = Trim(ws.Cells(r, errorCol).Value)
|
||||||
Dim errorCode As String: errorCode = GetCode(errorMessage)
|
Dim errorCode As String: errorCode = GetCode(errorMessage)
|
||||||
If errorCode <> "W001" And errorCode <> "" Then
|
If errorCode <> "W001" And errorCode <> "" Then
|
||||||
MsgBox errorMessage
|
|
||||||
errorCountOut = errorCountOut + 1
|
errorCountOut = errorCountOut + 1
|
||||||
End If
|
End If
|
||||||
Next r
|
Next r
|
||||||
|
|||||||
@@ -320,11 +320,111 @@ Public Function FormatDateInput(ByVal inputStr As String) As String
|
|||||||
End If
|
End If
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Function GetErrorMsg(ByVal errorCode As String, Optional ByVal param As String = "") As String
|
Function GetErrorMsg(ByVal errorCode As String, Optional ByVal param0 As String = "", Optional ByVal param1 As String = "") As String
|
||||||
Dim errorList As Object: Set errorList = GetErrorList()
|
Dim errorList As Object: Set errorList = GetErrorList()
|
||||||
Dim errorMessage As String
|
Dim errorMessage As String
|
||||||
If errorList.Exists(errorCode) Then
|
If errorList.Exists(errorCode) Then
|
||||||
errorMessage = MakeSelect(errorCode, Replace(errorList(errorCode)(0), "{0}", param))
|
errorMessage = Replace(errorList(errorCode)(0), "{0}", param0)
|
||||||
|
errorMessage = Replace(errorMessage, "{1}", param1)
|
||||||
|
errorMessage = MakeSelect(errorCode, errorMessage)
|
||||||
End If
|
End If
|
||||||
GetErrorMsg = errorMessage
|
GetErrorMsg = errorMessage
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Function ColLetter(colNum As Long) As String
|
||||||
|
ColLetter = Split(Cells(1, colNum).Address, "$")(1)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Function CheckRequired(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)
|
||||||
|
If checkValue = "" Then
|
||||||
|
Dim letter As String: letter = ColLetter(colNum)
|
||||||
|
ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E002", letter & rowNum)
|
||||||
|
ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0)
|
||||||
|
CheckRequired = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
CheckRequired = True
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Function CheckChar(ByVal ws As Worksheet, ByVal rowNum As Long, ByVal colNum As Long, ByVal charLength As Long, ByVal errorCol As String)
|
||||||
|
Dim checkValue As String: checkValue = Trim(ws.Cells(rowNum, colNum).Value)
|
||||||
|
If Len(checkValue) <> charLength Then
|
||||||
|
Dim letter As String: letter = ColLetter(colNum)
|
||||||
|
ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E006", letter & rowNum, charLength)
|
||||||
|
ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0)
|
||||||
|
CheckChar = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
CheckChar = True
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Function CheckAlphanumeric(ByVal ws As Worksheet, ByVal rowNum As Long, ByVal colNum As Long, ByVal charLength As Long, ByVal errorCol As String)
|
||||||
|
Dim checkValue As String: checkValue = Trim(ws.Cells(rowNum, colNum).Value)
|
||||||
|
Dim letter As String: letter = ColLetter(colNum)
|
||||||
|
Dim i As Long
|
||||||
|
Dim ch As String
|
||||||
|
For i = 1 To charLength
|
||||||
|
ch = Mid(checkValue, i, 1)
|
||||||
|
If Not ((ch >= "0" And ch <= "9") Or (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z")) Then
|
||||||
|
ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E005", letter & rowNum)
|
||||||
|
ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0)
|
||||||
|
CheckAlphanumeric = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
Next i
|
||||||
|
|
||||||
|
CheckAlphanumeric = True
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Function CheckVarcharOver(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("E007", letter & rowNum)
|
||||||
|
ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0)
|
||||||
|
CheckVarcharOver = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
CheckVarcharOver = True
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Function Check01(ByVal ws As Worksheet, ByVal rowNum As Long, ByVal colNum As Long, ByVal errorCol As String)
|
||||||
|
Dim checkValue As String: checkValue = Trim(ws.Cells(rowNum, colNum).Value)
|
||||||
|
Dim letter As String: letter = ColLetter(colNum)
|
||||||
|
If checkValue <> "" Then
|
||||||
|
If Len(checkValue) <> 1 Then
|
||||||
|
ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E001", letter & rowNum)
|
||||||
|
ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0)
|
||||||
|
Check01 = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
If checkValue <> "0" And checkValue <> "1" Then
|
||||||
|
ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E008", letter & rowNum)
|
||||||
|
ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0)
|
||||||
|
Check01 = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
Check01 = True
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Function Check12(ByVal ws As Worksheet, ByVal rowNum As Long, ByVal colNum As Long, ByVal errorCol As String)
|
||||||
|
Dim checkValue As String: checkValue = Trim(ws.Cells(rowNum, colNum).Value)
|
||||||
|
Dim letter As String: letter = ColLetter(colNum)
|
||||||
|
If checkValue <> "" Then
|
||||||
|
If Len(checkValue) <> 1 Then
|
||||||
|
ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E001", letter & rowNum)
|
||||||
|
ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0)
|
||||||
|
Check12 = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
If checkValue <> "1" And checkValue <> "2" Then
|
||||||
|
ws.Cells(rowNum, errorCol).Value = GetErrorMsg("E009", letter & rowNum)
|
||||||
|
ws.Cells(rowNum, colNum).Interior.Color = RGB(255, 0, 0)
|
||||||
|
Check12 = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
Check12 = True
|
||||||
|
End Function
|
||||||
|
|||||||
@@ -401,6 +401,7 @@ End Sub
|
|||||||
' higaitouList
|
' higaitouList
|
||||||
' ============================================================
|
' ============================================================
|
||||||
Private Sub RefreshErrorList()
|
Private Sub RefreshErrorList()
|
||||||
|
Set errorList = Nothing
|
||||||
On Error GoTo RefreshError
|
On Error GoTo RefreshError
|
||||||
Set errorList = LoadLookup("Enum", keyCol:=18, valueCols:=Array(19), startRow:=3)
|
Set errorList = LoadLookup("Enum", keyCol:=18, valueCols:=Array(19), startRow:=3)
|
||||||
On Error GoTo 0
|
On Error GoTo 0
|
||||||
|
|||||||
127
src/sheet/Z1.cls
127
src/sheet/Z1.cls
@@ -18,94 +18,47 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
|||||||
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
||||||
clearRange.Interior.Color = vbWhite
|
clearRange.Interior.Color = vbWhite
|
||||||
|
|
||||||
Dim cValue As String: cValue = Trim(ws.Cells(rowNum, 3).Value)
|
Dim checkResult As Boolean: checkResult = False
|
||||||
If cValue = "" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column is required"
|
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
If Len(cValue) <> 3 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column must be 3 characters"
|
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim i As Long
|
|
||||||
Dim ch As String
|
|
||||||
For i = 1 To 3
|
|
||||||
ch = Mid(cValue, i, 1)
|
|
||||||
If Not ((ch >= "0" And ch <= "9") Or (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z")) Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column must be alphanumeric"
|
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
Next i
|
|
||||||
|
|
||||||
Dim dValue As String
|
|
||||||
dValue = Trim(ws.Cells(rowNum, 4).Value)
|
|
||||||
If dValue = "" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "D column is required"
|
|
||||||
ws.Cells(rowNum, 4).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If Len(dValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "D column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 4).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim eValue As String
|
|
||||||
eValue = Trim(ws.Cells(rowNum, 5).Value)
|
|
||||||
If eValue = "" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "E column is required"
|
|
||||||
ws.Cells(rowNum, 5).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If Len(eValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "E column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 5).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim fValue As String
|
|
||||||
fValue = Trim(ws.Cells(rowNum, 6).Value)
|
|
||||||
If fValue <> "" And Len(fValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "F column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 6).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim gValue As String
|
|
||||||
gValue = Trim(ws.Cells(rowNum, 7).Value)
|
|
||||||
If gValue <> "" And Len(gValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "G column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 7).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim hValue As String
|
|
||||||
hValue = Trim(ws.Cells(rowNum, 8).Value)
|
|
||||||
If hValue <> "" Then
|
|
||||||
If Len(hValue) <> 1 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "H column must be 1 digit"
|
|
||||||
ws.Cells(rowNum, 8).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If hValue <> "0" And hValue <> "1" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "H column must be 0 or 1"
|
|
||||||
ws.Cells(rowNum, 8).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim iValue As String
|
' C column check
|
||||||
iValue = Trim(ws.Cells(rowNum, 9).Value)
|
checkResult = CheckRequired(ws, rowNum, 3, errorCol)
|
||||||
If iValue <> "" And Len(iValue) > 80 Then
|
If checkResult = False Then Exit Sub
|
||||||
ws.Cells(rowNum, errorCol).Value = "I column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 9).Interior.Color = RGB(255, 0, 0)
|
checkResult = CheckChar(ws, rowNum, 3, 3, errorCol)
|
||||||
Exit Sub
|
If checkResult = False Then Exit Sub
|
||||||
End If
|
|
||||||
|
checkResult = CheckAlphanumeric(ws, rowNum, 3, 3, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' D column check
|
||||||
|
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 4, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' E column check
|
||||||
|
checkResult = CheckRequired(ws, rowNum, 5, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 5, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' F column check
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 6, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' G column check
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 7, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' H column check
|
||||||
|
checkResult = Check01(ws, rowNum, 8, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' I column check
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 9, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
ws.Cells(rowNum, errorCol).ClearContents
|
ws.Cells(rowNum, errorCol).ClearContents
|
||||||
End Sub
|
End Sub
|
||||||
|
|||||||
@@ -17,79 +17,38 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
|||||||
' clear C~I columns background color
|
' clear C~I columns background color
|
||||||
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
||||||
clearRange.Interior.Color = vbWhite
|
clearRange.Interior.Color = vbWhite
|
||||||
|
|
||||||
|
' C column check
|
||||||
|
checkResult = CheckRequired(ws, rowNum, 3, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckChar(ws, rowNum, 3, 1, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckAlphanumeric(ws, rowNum, 3, 1, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
Dim cValue As String: cValue = Trim(ws.Cells(rowNum, 3).Value)
|
' D column check
|
||||||
If cValue = "" Then
|
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column is required"
|
If checkResult = False Then Exit Sub
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
checkResult = CheckVarcharOver(ws, rowNum, 4, 80, errorCol)
|
||||||
End If
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' E column check
|
||||||
|
checkResult = CheckRequired(ws, rowNum, 5, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 5, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
If Len(cValue) <> 3 Then
|
' F column check
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column must be 3 characters"
|
checkResult = CheckVarcharOver(ws, rowNum, 6, 80, errorCol)
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
If checkResult = False Then Exit Sub
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim i As Long
|
' G column check
|
||||||
Dim ch As String
|
checkResult = Check01(ws, rowNum, 7, errorCol)
|
||||||
For i = 1 To 3
|
If checkResult = False Then Exit Sub
|
||||||
ch = Mid(cValue, i, 1)
|
|
||||||
If Not ((ch >= "0" And ch <= "9") Or (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z")) Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column must be alphanumeric"
|
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
Next i
|
|
||||||
|
|
||||||
Dim dValue As String
|
|
||||||
dValue = Trim(ws.Cells(rowNum, 4).Value)
|
|
||||||
If dValue = "" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "D column is required"
|
|
||||||
ws.Cells(rowNum, 4).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If Len(dValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "D column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 4).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim eValue As String
|
|
||||||
eValue = Trim(ws.Cells(rowNum, 5).Value)
|
|
||||||
If eValue = "" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "E column is required"
|
|
||||||
ws.Cells(rowNum, 5).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If Len(eValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "E column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 5).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim fValue As String
|
|
||||||
fValue = Trim(ws.Cells(rowNum, 6).Value)
|
|
||||||
If fValue <> "" And Len(fValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "F column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 6).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim hValue As String
|
|
||||||
hValue = Trim(ws.Cells(rowNum, 7).Value)
|
|
||||||
If hValue <> "" Then
|
|
||||||
If Len(hValue) <> 1 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "G column must be 1 digit"
|
|
||||||
ws.Cells(rowNum, 7).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If hValue <> "0" And hValue <> "1" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "G column must be 0 or 1"
|
|
||||||
ws.Cells(rowNum, 7).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
|
|
||||||
ws.Cells(rowNum, errorCol).ClearContents
|
ws.Cells(rowNum, errorCol).ClearContents
|
||||||
End Sub
|
End Sub
|
||||||
|
|||||||
115
src/sheet/Z3.cls
115
src/sheet/Z3.cls
@@ -17,86 +17,41 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
|||||||
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
||||||
clearRange.Interior.Color = vbWhite
|
clearRange.Interior.Color = vbWhite
|
||||||
|
|
||||||
Dim cValue As String: cValue = Trim(ws.Cells(rowNum, 3).Value)
|
' C column check
|
||||||
If cValue = "" Then
|
checkResult = CheckRequired(ws, rowNum, 3, errorCol)
|
||||||
ws.Cells(rowNum, endCol).Value = "C column is required"
|
If checkResult = False Then Exit Sub
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
If Len(cValue) <> 3 Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "C column must be 3 characters"
|
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim i As Long
|
|
||||||
Dim ch As String
|
|
||||||
For i = 1 To 3
|
|
||||||
ch = Mid(cValue, i, 1)
|
|
||||||
If Not ((ch >= "0" And ch <= "9") Or (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z")) Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "C column must be alphanumeric"
|
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
Next i
|
|
||||||
|
|
||||||
Dim dValue As String
|
|
||||||
dValue = Trim(ws.Cells(rowNum, 4).Value)
|
|
||||||
If dValue = "" Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "D column is required"
|
|
||||||
ws.Cells(rowNum, 4).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If Len(dValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "D column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 4).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim eValue As String
|
|
||||||
eValue = Trim(ws.Cells(rowNum, 5).Value)
|
|
||||||
If eValue = "" Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "E column is required"
|
|
||||||
ws.Cells(rowNum, 5).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If Len(eValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "E column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 5).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim fValue As String
|
|
||||||
fValue = Trim(ws.Cells(rowNum, 6).Value)
|
|
||||||
If fValue <> "" And Len(fValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "F column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 6).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim hValue As String
|
|
||||||
hValue = Trim(ws.Cells(rowNum, 7).Value)
|
|
||||||
If hValue <> "" Then
|
|
||||||
If Len(hValue) <> 1 Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "G column must be 1 digit"
|
|
||||||
ws.Cells(rowNum, 7).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If hValue <> "0" And hValue <> "1" Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "G column must be 0 or 1"
|
|
||||||
ws.Cells(rowNum, 7).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim iValue As String
|
checkResult = CheckChar(ws, rowNum, 3, 2, errorCol)
|
||||||
iValue = Trim(ws.Cells(rowNum, 8).Value)
|
If checkResult = False Then Exit Sub
|
||||||
If iValue <> "" And Len(iValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, endCol).Value = "H column must be within 80 characters"
|
checkResult = CheckAlphanumeric(ws, rowNum, 3, 2, errorCol)
|
||||||
ws.Cells(rowNum, 8).Interior.Color = RGB(255, 0, 0)
|
If checkResult = False Then Exit Sub
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
ws.Cells(rowNum, endCol).ClearContents
|
' D column check
|
||||||
|
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 4, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' E column check
|
||||||
|
checkResult = CheckRequired(ws, rowNum, 5, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 5, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' F column check
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 6, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' G column check
|
||||||
|
checkResult = Check01(ws, rowNum, 7, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' H column check
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 8, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
ws.Cells(rowNum, errorCol).ClearContents
|
||||||
End Sub
|
End Sub
|
||||||
|
|||||||
117
src/sheet/Z4.cls
117
src/sheet/Z4.cls
@@ -17,86 +17,45 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
|||||||
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
||||||
clearRange.Interior.Color = vbWhite
|
clearRange.Interior.Color = vbWhite
|
||||||
|
|
||||||
Dim cValue As String: cValue = Trim(ws.Cells(rowNum, 3).Value)
|
' C column check
|
||||||
If cValue = "" Then
|
checkResult = CheckRequired(ws, rowNum, 3, errorCol)
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column is required"
|
If checkResult = False Then Exit Sub
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
If Len(cValue) <> 3 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column must be 3 characters"
|
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim i As Long
|
|
||||||
Dim ch As String
|
|
||||||
For i = 1 To 3
|
|
||||||
ch = Mid(cValue, i, 1)
|
|
||||||
If Not ((ch >= "0" And ch <= "9") Or (ch >= "A" And ch <= "Z") Or (ch >= "a" And ch <= "z")) Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "C column must be alphanumeric"
|
|
||||||
ws.Cells(rowNum, 3).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
Next i
|
|
||||||
|
|
||||||
Dim dValue As String
|
|
||||||
dValue = Trim(ws.Cells(rowNum, 4).Value)
|
|
||||||
If dValue = "" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "D column is required"
|
|
||||||
ws.Cells(rowNum, 4).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If Len(dValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "D column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 4).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim eValue As String
|
|
||||||
eValue = Trim(ws.Cells(rowNum, 5).Value)
|
|
||||||
If eValue = "" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "E column is required"
|
|
||||||
ws.Cells(rowNum, 5).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If Len(eValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "E column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 5).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim fValue As String
|
|
||||||
fValue = Trim(ws.Cells(rowNum, 6).Value)
|
|
||||||
If fValue <> "" And Len(fValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "F column must be within 80 characters"
|
|
||||||
ws.Cells(rowNum, 6).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim hValue As String
|
|
||||||
hValue = Trim(ws.Cells(rowNum, 7).Value)
|
|
||||||
If hValue <> "" Then
|
|
||||||
If Len(hValue) <> 1 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "G column must be 1 digit"
|
|
||||||
ws.Cells(rowNum, 7).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
If hValue <> "0" And hValue <> "1" Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "G column must be 0 or 1"
|
|
||||||
ws.Cells(rowNum, 7).Interior.Color = RGB(255, 0, 0)
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim iValue As String
|
checkResult = CheckChar(ws, rowNum, 3, 2, errorCol)
|
||||||
iValue = Trim(ws.Cells(rowNum, 8).Value)
|
If checkResult = False Then Exit Sub
|
||||||
If iValue <> "" And Len(iValue) > 80 Then
|
|
||||||
ws.Cells(rowNum, errorCol).Value = "H column must be within 80 characters"
|
checkResult = CheckAlphanumeric(ws, rowNum, 3, 2, errorCol)
|
||||||
ws.Cells(rowNum, 8).Interior.Color = RGB(255, 0, 0)
|
If checkResult = False Then Exit Sub
|
||||||
Exit Sub
|
|
||||||
End If
|
' D column check
|
||||||
|
checkResult = CheckRequired(ws, rowNum, 4, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 4, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' E column check
|
||||||
|
checkResult = CheckRequired(ws, rowNum, 5, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 5, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' F column check
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 6, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' G column check
|
||||||
|
checkResult = Check01(ws, rowNum, 7, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' H column check
|
||||||
|
checkResult = CheckVarcharOver(ws, rowNum, 8, 80, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
|
' I column check
|
||||||
|
checkResult = Check12(ws, rowNum, 9, errorCol)
|
||||||
|
If checkResult = False Then Exit Sub
|
||||||
|
|
||||||
ws.Cells(rowNum, errorCol).ClearContents
|
ws.Cells(rowNum, errorCol).ClearContents
|
||||||
End Sub
|
End Sub
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user