cache refactor
This commit is contained in:
@@ -8,6 +8,11 @@
|
||||
' - Validate
|
||||
' ============================================================
|
||||
Private Sub Worksheet_Change(ByVal Target As Range)
|
||||
Dim HasHeaderEdit As Boolean: HasHeaderEdit = CheckHeaderEdit(Me, Target)
|
||||
If HasHeaderEdit = True Then Exit Sub
|
||||
|
||||
If Target.EntireRow.Address = Target.Address Then Exit Sub
|
||||
|
||||
Dim watchArea As Range
|
||||
With Me
|
||||
Set watchArea = Union( _
|
||||
@@ -29,6 +34,7 @@ Private Sub Worksheet_Change(ByVal Target As Range)
|
||||
For Each cell In Target
|
||||
If Trim(cell.Value) = "" Then
|
||||
Call ClearRowData(Me, cell.Row)
|
||||
GoTo Finally
|
||||
Else
|
||||
Call FillFromM1(cell.Row)
|
||||
End If
|
||||
@@ -95,11 +101,11 @@ Private Sub FillKFromJ(ByVal rowNum As Long)
|
||||
Dim cache As Object
|
||||
Select Case iValue
|
||||
Case "1"
|
||||
Set cache = GetT1Cache()
|
||||
Set cache = GetCache("T1")
|
||||
Case "2"
|
||||
Set cache = GetT2Cache()
|
||||
Set cache = GetCache("T2")
|
||||
Case "3"
|
||||
Set cache = GetT3Cache()
|
||||
Set cache = GetCache("T3")
|
||||
Case Else
|
||||
Exit Sub
|
||||
End Select
|
||||
@@ -145,14 +151,14 @@ Private Sub CreateJDropdown(ByVal rowNum As Long)
|
||||
Dim cache As Object
|
||||
Select Case iValue
|
||||
Case "1"
|
||||
Set cache = GetT1Cache()
|
||||
Set cache = GetCache("T1")
|
||||
Me.Range("O" & rowNum).Interior.Color = RGB(192, 192, 192)
|
||||
Me.Range("P" & rowNum).Interior.Color = RGB(192, 192, 192)
|
||||
Me.Range("Q" & rowNum).Interior.Color = RGB(192, 192, 192)
|
||||
Case "2"
|
||||
Set cache = GetT2Cache()
|
||||
Set cache = GetCache("T2")
|
||||
Case "3"
|
||||
Set cache = GetT3Cache()
|
||||
Set cache = GetCache("T3")
|
||||
Me.Range("N" & rowNum).Interior.Color = RGB(192, 192, 192)
|
||||
Me.Range("O" & rowNum).Interior.Color = RGB(192, 192, 192)
|
||||
Me.Range("P" & rowNum).Interior.Color = RGB(192, 192, 192)
|
||||
@@ -187,7 +193,7 @@ End Sub
|
||||
Private Sub FillFromM1(ByVal rowNum As Long)
|
||||
Set ws = Me
|
||||
|
||||
Dim m1Cache As Object: Set m1Cache = GetM1Cache()
|
||||
Dim m1Cache As Object: Set m1Cache = GetCache("M1")
|
||||
Dim cValue As String: cValue = Trim(ws.Range("C" & rowNum).Value)
|
||||
|
||||
' Fill D, E, F, G, H columns from M1 cache
|
||||
@@ -223,9 +229,10 @@ End Sub
|
||||
|
||||
Private Sub ClearRowData(ByVal ws As Worksheet, ByVal rowNum As Long)
|
||||
' Clear from D column onwards
|
||||
ws.Range(ws.Cells(rowNum, 4), ws.Cells(rowNum, 15)).ClearContents
|
||||
ws.Cells(rowNum, 6).Validation.Delete
|
||||
ws.Cells(rowNum, 19).ClearContents ' Q column error info
|
||||
ws.Range(ws.Cells(rowNum, "D"), ws.Cells(rowNum, "R")).ClearContents
|
||||
ws.Range(ws.Cells(rowNum, "C"), ws.Cells(rowNum, "R")).Interior.Color = vbWhite
|
||||
ws.Cells(rowNum, "J").Validation.Delete
|
||||
ws.Cells(rowNum, "S").ClearContents
|
||||
End Sub
|
||||
|
||||
Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As Long)
|
||||
@@ -241,19 +248,19 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
||||
clearRange.Interior.Color = vbWhite
|
||||
|
||||
' Check C column in the cache
|
||||
Dim m1Cache As Object: Set m1Cache = GetM1Cache()
|
||||
Dim m1Cache As Object: Set m1Cache = GetCache("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
|
||||
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("I", "J", "K", "L", "M")
|
||||
@@ -277,7 +284,7 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
||||
Next col
|
||||
|
||||
' Check I column in the kenshuKbn
|
||||
Dim kenshuList As Object: Set kenshuList = GetKenshuList()
|
||||
Dim kenshuList As Object: Set kenshuList = GetCache("kenshuList")
|
||||
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)
|
||||
@@ -299,7 +306,7 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
||||
Dim equaledCols As Variant
|
||||
Dim emptyCols As Variant
|
||||
If kenshuKbn = "1" Then
|
||||
Set cache = GetT1Cache()
|
||||
Set cache = GetCache("T1")
|
||||
' must input
|
||||
equaledCols = Array("K")
|
||||
requiredCols = Array("N")
|
||||
@@ -307,7 +314,7 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
||||
End If
|
||||
|
||||
If kenshuKbn = "2" Then
|
||||
Set cache = GetT2Cache()
|
||||
Set cache = GetCache("T2")
|
||||
' must input
|
||||
equaledCols = Array("K", "L", "M", "N", "O", "P", "Q")
|
||||
requiredCols = Array("N", "O", "P", "Q")
|
||||
@@ -315,7 +322,7 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
||||
End If
|
||||
|
||||
If kenshuKbn = "3" Then
|
||||
Set cache = GetT3Cache()
|
||||
Set cache = GetCache("T3")
|
||||
' must input
|
||||
equaledCols = Array("K", "L", "M")
|
||||
requiredCols = Array()
|
||||
@@ -381,6 +388,13 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
||||
|
||||
End Sub
|
||||
|
||||
Sub ImportCSVAndTriggerChange(ws As Worksheet)
|
||||
' TODO
|
||||
Public Sub ImportCSVAndTriggerChange(ws As Worksheet, ByVal lastDataRow As Long)
|
||||
Dim sheetConfDict As Object: Set sheetConfDict = GetSheetConfig()
|
||||
Dim sheetConf As Object: Set sheetConf = sheetConfDict(ws.CodeName)
|
||||
|
||||
Dim startRow As Long: startRow = sheetConf("StartRow")
|
||||
Dim i As Long
|
||||
For i = startRow To lastDataRow
|
||||
Call FillFromM1(i)
|
||||
Next i
|
||||
End Sub
|
||||
|
||||
Reference in New Issue
Block a user