refactor
This commit is contained in:
@@ -108,6 +108,7 @@ Private Sub Worksheet_Change(ByVal Target As Range)
|
||||
If intersectRng Is Nothing Then Exit Sub
|
||||
|
||||
If Target.Row < 7 Then Exit Sub
|
||||
Dim idx As Long
|
||||
|
||||
Application.EnableEvents = False
|
||||
On Error GoTo Finally
|
||||
@@ -139,7 +140,6 @@ Private Sub Worksheet_Change(ByVal Target As Range)
|
||||
End If
|
||||
|
||||
' === Transport column changes (T, AA, AH, AO) ===
|
||||
Dim idx As Long
|
||||
idx = GetIdx(Target.Column, KUKAN_TRANSPORT_COLS)
|
||||
If idx >= 0 Then
|
||||
Dim cellT As Range
|
||||
@@ -260,7 +260,7 @@ End Sub
|
||||
|
||||
' Fill kukan info from M1 cache (key: kukan code, value: 7 elements)
|
||||
Private Sub FillKukanFromM1(ByVal rowNum As Long, ByVal idx As Long)
|
||||
If m1Cache Is Nothing Then Call RefreshM1Cache
|
||||
Dim m1Cache As Object: Set m1Cache = GetM1Cache()
|
||||
|
||||
Dim codeCol As Long: codeCol = KUKAN_CODE_COLS(idx)
|
||||
Dim transportCol As Long: transportCol = KUKAN_TRANSPORT_COLS(idx)
|
||||
@@ -293,7 +293,7 @@ End Sub
|
||||
|
||||
' Fill address dropdown from O1 cache
|
||||
Private Sub FillAddressFromO1(ByVal rowNum As Long)
|
||||
If o1Cache Is Nothing Then Call RefreshO1Cache
|
||||
Dim o1Cache As Object: Set o1Cache = GetO1Cache()
|
||||
|
||||
Dim empNo As String
|
||||
empNo = Trim(Me.Cells(rowNum, 3).Value)
|
||||
@@ -329,7 +329,7 @@ End Sub
|
||||
|
||||
' Create station (利用区間発) dropdown from M1_KukanD cache
|
||||
Private Sub CreateFromStationDropdown(ByVal rowNum As Long, ByVal transportCol As Long, ByVal stationCol As Long)
|
||||
If m1KukanDCache Is Nothing Then Call RefreshM1KukanDCache
|
||||
Dim m1KukanDCache As Object: Set m1KukanDCache = GetM1KukanDCache()
|
||||
|
||||
Dim transport As String: transport = GetCode(Me.Cells(rowNum, transportCol).Value)
|
||||
If transport = "" Then Exit Sub
|
||||
@@ -361,7 +361,7 @@ End Sub
|
||||
' Create destination (利用区間着) dropdown from M1_KukanD cache
|
||||
' Structure: { D: { F: [G] } }
|
||||
Private Sub CreateToStationDropdown(ByVal rowNum As Long, ByVal transportCol As Long, ByVal stationFromCol As Long, ByVal stationToCol As Long)
|
||||
If m1KukanDCache Is Nothing Then Call RefreshM1KukanDCache
|
||||
Dim m1KukanDCache As Object: Set m1KukanDCache = GetM1KukanDCache()
|
||||
|
||||
Dim transport As String: transport = GetCode(Me.Cells(rowNum, transportCol).Value)
|
||||
Dim stationFrom As String: stationFrom = GetCode(Me.Cells(rowNum, stationFromCol).Value)
|
||||
@@ -396,7 +396,7 @@ End Sub
|
||||
|
||||
' Find kukan code by transport + station_from + station_to (reverse lookup)
|
||||
Private Function FindKukanCodeByStation(ByVal rowNum As Long, ByVal transportCol As Long, ByVal stationFromCol As Long, ByVal stationToCol As Long) As String
|
||||
If m1Cache Is Nothing Then Call RefreshM1Cache
|
||||
Dim m1Cache As Object: Set m1Cache = GetM1Cache()
|
||||
|
||||
Dim transportKbn As String: transportKbn = GetCode(Trim(Me.Cells(rowNum, transportCol).Value))
|
||||
Dim stationFrom As String: stationFrom = Trim(Me.Cells(rowNum, stationFromCol).Value)
|
||||
@@ -427,7 +427,7 @@ End Sub
|
||||
|
||||
' Create dropdown from M2 cache: get code (J列) list for kukanCode + kanshu
|
||||
Private Sub CreateM2CodeDropdown(ByVal rowNum As Long, ByVal kukanCodeCol As Long, ByVal kanshuCol As Long, ByVal codeCol As Long)
|
||||
If m2Cache Is Nothing Then Call RefreshM2Cache
|
||||
Dim m2Cache As Object: Set m2Cache = GetM2Cache()
|
||||
|
||||
Dim kukanCode As String: kukanCode = Trim(Me.Cells(rowNum, kukanCodeCol).Value)
|
||||
Dim kanshu As String: kanshu = Trim(Me.Cells(rowNum, kanshuCol).Value)
|
||||
@@ -465,34 +465,19 @@ Private Sub ClearRowData(ByVal rowNum As Long)
|
||||
Me.Cells(rowNum, ERROR_COL).ClearContents
|
||||
End Sub
|
||||
|
||||
' ====== Button Macros ======
|
||||
Private Sub validateButton()
|
||||
Dim lastRow As Long, r As Long, errorCount As Long
|
||||
lastRow = GetLastDataRowInRange(Me, START_COL, END_COL)
|
||||
|
||||
If lastRow < 7 Then
|
||||
MsgBox "No data found.", vbExclamation
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
errorCount = 0
|
||||
For r = 7 To lastRow
|
||||
Call Validate(r)
|
||||
If Trim(Cells(r, ERROR_COL).Value) <> "" Then
|
||||
errorCount = errorCount + 1
|
||||
End If
|
||||
Next r
|
||||
|
||||
MsgBox "Validation complete. Errors: " & errorCount, vbInformation
|
||||
End Sub
|
||||
|
||||
' Validation logic
|
||||
Private Private Sub validate(ByVal rowNum As Long)
|
||||
Set ws = Me
|
||||
|
||||
' Clear background color
|
||||
Me.Range(Me.Cells(rowNum, START_COL), Me.Cells(rowNum, END_COL)).Interior.Color = vbWhite
|
||||
|
||||
Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As Long)
|
||||
|
||||
Dim sheetConfDict As Object: Set sheetConfDict = GetSheetConfig()
|
||||
Dim sheetConf As Object: Set sheetConf = sheetConfDict(ws.CodeName)
|
||||
|
||||
Dim startCol As String: startCol = sheetConf("StartCol")
|
||||
Dim endCol As String: endCol = sheetConf("EndCol")
|
||||
Dim errorCol As String: errorCol = sheetConf("ErrorCol")
|
||||
|
||||
Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
|
||||
clearRange.Interior.Color = vbWhite
|
||||
|
||||
' Required columns: C-G, K-N, AW
|
||||
Dim requiredCols As Variant
|
||||
requiredCols = Array("C", "D", "E", "F", "G", "K", "L", "M", "N", "AW")
|
||||
@@ -507,15 +492,3 @@ Private Private Sub validate(ByVal rowNum As Long)
|
||||
|
||||
Me.Cells(rowNum, ERROR_COL).ClearContents
|
||||
End Sub
|
||||
|
||||
Private Sub Do_Sort()
|
||||
Call SortDataRows(3)
|
||||
End Sub
|
||||
|
||||
Private Sub Do_Filter()
|
||||
Call ToggleAutoFilter(START_COL, END_COL)
|
||||
End Sub
|
||||
|
||||
Private Sub Do_Fit()
|
||||
Call AutoFitColumnWidth(START_COL, END_COL)
|
||||
End Sub
|
||||
|
||||
Reference in New Issue
Block a user