Update Z1 validation - C column must be 3-digit alphanumeric, error in column B
This commit is contained in:
@@ -151,75 +151,35 @@ Function CleanCSVField(ByVal field As Variant) As String
|
||||
End Function
|
||||
|
||||
Sub validateDetailData(ByVal ws As Worksheet, ByVal rowNum As Long)
|
||||
' Check C column not empty
|
||||
If Trim(ws.Cells(rowNum, 3).Value) = "" Then
|
||||
ws.Cells(rowNum, 19).ClearContents
|
||||
' Check C column - must be 3-digit alphanumeric, required
|
||||
Dim cValue As String
|
||||
cValue = Trim(ws.Cells(rowNum, 3).Value)
|
||||
|
||||
If cValue = "" Then
|
||||
ws.Cells(rowNum, 2).Value = "C column is required"
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' Check G, H required and numeric (for composite key)
|
||||
If Trim(ws.Cells(rowNum, 9).Value) = "" Or Not IsNumeric(ws.Cells(rowNum, 9).Value) Then
|
||||
ws.Cells(rowNum, 19).Value = "G column (I) is required and must be numeric"
|
||||
If Len(cValue) <> 3 Then
|
||||
ws.Cells(rowNum, 2).Value = "C column must be 3 characters"
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
If Trim(ws.Cells(rowNum, 10).Value) = "" Or Not IsNumeric(ws.Cells(rowNum, 10).Value) Then
|
||||
ws.Cells(rowNum, 19).Value = "H column (J) is required and must be numeric"
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' Check I (K column) required
|
||||
If Trim(ws.Cells(rowNum, 11).Value) = "" Then
|
||||
ws.Cells(rowNum, 19).Value = "I column (K) is required"
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' Check J, K required and numeric
|
||||
If Trim(ws.Cells(rowNum, 12).Value) = "" Or Not IsNumeric(ws.Cells(rowNum, 12).Value) Then
|
||||
ws.Cells(rowNum, 19).Value = "J column (L) is required and must be numeric"
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
If Trim(ws.Cells(rowNum, 13).Value) = "" Or Not IsNumeric(ws.Cells(rowNum, 13).Value) Then
|
||||
ws.Cells(rowNum, 19).Value = "K column (M) is required and must be numeric"
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' Check L-P optional but must be numeric if entered
|
||||
Dim col As Long
|
||||
Dim colName As String
|
||||
Dim colLetter As String
|
||||
colLetter = "NOPQR"
|
||||
|
||||
For col = 14 To 18
|
||||
If Trim(ws.Cells(rowNum, col).Value) <> "" And Not IsNumeric(ws.Cells(rowNum, col).Value) Then
|
||||
colName = Mid(colLetter, col - 13, 1)
|
||||
ws.Cells(rowNum, 19).Value = colName & " column must be numeric"
|
||||
Exit Sub
|
||||
End If
|
||||
Next col
|
||||
|
||||
' Check GH composite key duplicate
|
||||
Dim g As String, h As String
|
||||
Dim r As Long
|
||||
Dim lastRow As Long
|
||||
|
||||
g = Trim(ws.Cells(rowNum, 9).Value)
|
||||
h = Trim(ws.Cells(rowNum, 10).Value)
|
||||
|
||||
lastRow = ws.Cells(ws.Rows.Count, 3).End(xlUp).Row
|
||||
|
||||
For r = 7 To lastRow
|
||||
If r <> rowNum And Trim(ws.Cells(r, 3).Value) = Trim(ws.Cells(rowNum, 3).Value) Then
|
||||
If Trim(ws.Cells(r, 9).Value) = g And Trim(ws.Cells(r, 10).Value) = h Then
|
||||
ws.Cells(rowNum, 19).Value = "GH (I,J) combination already exists"
|
||||
If Not IsNumeric(cValue) And Len(cValue) = 3 Then
|
||||
' Check if all characters are alphanumeric
|
||||
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, 2).Value = "C column must be alphanumeric"
|
||||
Exit Sub
|
||||
End If
|
||||
End If
|
||||
Next r
|
||||
Next i
|
||||
End If
|
||||
|
||||
' Validation passed
|
||||
ws.Cells(rowNum, 19).ClearContents
|
||||
ws.Cells(rowNum, 2).ClearContents
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -241,7 +201,7 @@ Sub validateDetailDataButton()
|
||||
errorCount = 0
|
||||
For r = 7 To lastRow
|
||||
Call validateDetailData(ws, r)
|
||||
If Trim(ws.Cells(r, 17).Value) <> "" Then
|
||||
If Trim(ws.Cells(r, 2).Value) <> "" Then
|
||||
errorCount = errorCount + 1
|
||||
End If
|
||||
Next r
|
||||
|
||||
Reference in New Issue
Block a user