20260515指摘対応10
This commit is contained in:
@@ -411,6 +411,4 @@ End Function
|
|||||||
Public Sub HandleError(Optional ByVal sourceProcedure As String = "")
|
Public Sub HandleError(Optional ByVal sourceProcedure As String = "")
|
||||||
Dim shortCode As String: shortCode = Right("0000" & CStr(Err.Number - vbObjectError), 4)
|
Dim shortCode As String: shortCode = Right("0000" & CStr(Err.Number - vbObjectError), 4)
|
||||||
MsgBox "[ERROR] " & shortCode & " : " & Err.Description, vbExclamation
|
MsgBox "[ERROR] " & shortCode & " : " & Err.Description, vbExclamation
|
||||||
|
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|||||||
@@ -596,8 +596,8 @@ Public Sub WriteCachesSheet(ByVal cacheName As String)
|
|||||||
Case "T1": colLetter = "E"
|
Case "T1": colLetter = "E"
|
||||||
Case "T2": colLetter = "F"
|
Case "T2": colLetter = "F"
|
||||||
Case "T3": colLetter = "G"
|
Case "T3": colLetter = "G"
|
||||||
Case "O1": colLetter = "H"
|
Case "O2": colLetter = "H"
|
||||||
Case "O2": colLetter = "I"
|
Case "M1": colLetter = "I"
|
||||||
Case Else: Exit Sub
|
Case Else: Exit Sub
|
||||||
End Select
|
End Select
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
' - FillKukanFromM1
|
' - FillKukanFromM1
|
||||||
' - FillKanshuFromM2
|
' - FillKanshuFromM2
|
||||||
' - FillCodeFromM2
|
' - FillCodeFromM2
|
||||||
' - CreateAddress1Dropdown
|
' - BuildAddress1Dropdown
|
||||||
' - FillZ1Dropdown
|
' - FillZ1Dropdown
|
||||||
' ============================================================
|
' ============================================================
|
||||||
' ====== (Tukin_C1) =======
|
' ====== (Tukin_C1) =======
|
||||||
@@ -102,11 +102,10 @@ Private Sub Worksheet_Change(ByVal Target As Range)
|
|||||||
If Target.Row < 8 Then Exit Sub
|
If Target.Row < 8 Then Exit Sub
|
||||||
Dim idx As Long
|
Dim idx As Long
|
||||||
|
|
||||||
|
' Check if cache is loaded
|
||||||
Application.EnableEvents = False
|
Application.EnableEvents = False
|
||||||
On Error GoTo Finally
|
On Error GoTo Finally
|
||||||
|
Dim testCache As Object: Set testCache = GetCache("Z1")
|
||||||
' === 3. rebuild dropdown list ===
|
|
||||||
Call RebuildDropdownsForTarget(Target)
|
|
||||||
|
|
||||||
' === Column C changes ===
|
' === Column C changes ===
|
||||||
If Target.Column = 3 Then
|
If Target.Column = 3 Then
|
||||||
@@ -116,7 +115,12 @@ Private Sub Worksheet_Change(ByVal Target As Range)
|
|||||||
If cshainno = "" Then
|
If cshainno = "" Then
|
||||||
Call ClearRowData(cell.Row)
|
Call ClearRowData(cell.Row)
|
||||||
Else
|
Else
|
||||||
Call CreateAddress1Dropdown(cell.Row, cshainno)
|
' rebuild dropdown list
|
||||||
|
Call BuildAddress1Dropdown(cell.Row, cshainno)
|
||||||
|
Call ReFillAddress1(cell.Row, cshainno)
|
||||||
|
Call BuildAddress2Dropdown(cell.Row, cshainno)
|
||||||
|
Call ReFillAddress2(cell.Row, cshainno)
|
||||||
|
Call RebuildDropdowns(cell.Row)
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
End If
|
End If
|
||||||
@@ -141,7 +145,7 @@ Private Sub Worksheet_Change(ByVal Target As Range)
|
|||||||
If Target.Column = 9 Then
|
If Target.Column = 9 Then
|
||||||
Dim cellI As Range
|
Dim cellI As Range
|
||||||
For Each cellI In Target
|
For Each cellI In Target
|
||||||
Call CreateAddress2Dropdown(cellI.Row)
|
Call BuildAddress2Dropdown(cellI.Row, Trim(Me.Cells(cellI.Row, CSHAINNO_COL).Value))
|
||||||
Next
|
Next
|
||||||
End If
|
End If
|
||||||
|
|
||||||
@@ -228,7 +232,11 @@ Private Sub Worksheet_Change(ByVal Target As Range)
|
|||||||
Next
|
Next
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
Application.EnableEvents = True
|
||||||
|
Exit Sub
|
||||||
|
|
||||||
Finally:
|
Finally:
|
||||||
|
HandleError "Worksheet_Change"
|
||||||
Application.EnableEvents = True '
|
Application.EnableEvents = True '
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
@@ -244,23 +252,32 @@ Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
|
|||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub RebuildDropdownsForTarget(ByVal Target As Range)
|
Private Sub Refresh(ws As Worksheet, ByVal startRow As Long, ByVal lastDataRow As Long)
|
||||||
If Target Is Nothing Then Exit Sub
|
Dim z1Cache As Object: Set z1Cache = GetCache("Z1")
|
||||||
|
|
||||||
Dim cell As Range
|
Application.EnableEvents = False
|
||||||
Dim processedRows As Object
|
On Error GoTo ErrorHandler
|
||||||
Set processedRows = CreateObject("Scripting.Dictionary")
|
|
||||||
|
|
||||||
For Each cell In Target
|
|
||||||
Dim r As Long
|
Dim r As Long
|
||||||
r = cell.Row
|
For r = startRow To lastDataRow
|
||||||
|
Dim cshainno As String: cshainno = Trim(Me.Cells(r, CSHAINNO_COL).Value)
|
||||||
|
Call BuildAddress1Dropdown(r, cshainno)
|
||||||
|
Call ReFillAddress1(r, cshainno)
|
||||||
|
Call BuildAddress2Dropdown(r, cshainno)
|
||||||
|
Call ReFillAddress2(r, cshainno)
|
||||||
|
Call RebuildDropdowns(r)
|
||||||
|
Call ReFillFromDropdowns(r)
|
||||||
|
Next r
|
||||||
|
|
||||||
If Not processedRows.Exists(r) Then
|
Application.EnableEvents = True
|
||||||
processedRows(r) = True
|
Exit Sub
|
||||||
|
|
||||||
Dim colLetter As String
|
ErrorHandler:
|
||||||
colLetter = Split(Me.Cells(1, cell.Column).Address(True, False), "$")(0)
|
Application.EnableEvents = True
|
||||||
|
Err.Raise ERR_CACHE_NOT_FOUND, "M1.Refresh", "Failed to refresh M1: " & Err.Description
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub RebuildDropdowns(ByVal rowNum As Long)
|
||||||
Dim dropdowns As Variant
|
Dim dropdowns As Variant
|
||||||
dropdowns = Array( _
|
dropdowns = Array( _
|
||||||
Array("T", "BuildTransportList"), _
|
Array("T", "BuildTransportList"), _
|
||||||
@@ -278,19 +295,57 @@ Private Sub RebuildDropdownsForTarget(ByVal Target As Range)
|
|||||||
|
|
||||||
Dim i As Long
|
Dim i As Long
|
||||||
For i = LBound(dropdowns) To UBound(dropdowns)
|
For i = LBound(dropdowns) To UBound(dropdowns)
|
||||||
If colLetter <> dropdowns(i)(0) Then
|
With Me.Cells(rowNum, dropdowns(i)(0)).Validation
|
||||||
With Me.Cells(r, dropdowns(i)(0)).Validation
|
|
||||||
.Delete
|
.Delete
|
||||||
.Add Type:=xlValidateList, Formula1:=Application.Run(dropdowns(i)(1))
|
.Add Type:=xlValidateList, Formula1:=Application.Run(dropdowns(i)(1))
|
||||||
.IgnoreBlank = True
|
.IgnoreBlank = True
|
||||||
.InCellDropdown = True
|
.InCellDropdown = True
|
||||||
End With
|
End With
|
||||||
End If
|
|
||||||
Next i
|
Next i
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub ReFillFromDropdowns(ByVal rowNum As Long)
|
||||||
|
Dim dropdowns As Variant
|
||||||
|
dropdowns = Array( _
|
||||||
|
Array("T", "BuildTransportList"), _
|
||||||
|
Array("AA", "BuildTransportList"), _
|
||||||
|
Array("AH", "BuildTransportList"), _
|
||||||
|
Array("AO", "BuildTransportList"), _
|
||||||
|
Array("G", "BuildTodokeList"), _
|
||||||
|
Array("M", "BuildOufukuList"), _
|
||||||
|
Array("N", "BuildKoutaiList"), _
|
||||||
|
Array("AU", "BuildKetteiList"), _
|
||||||
|
Array("AW", "BuildHigaitouList"), _
|
||||||
|
Array("AX", "BuildMonthAmountKbnList"), _
|
||||||
|
Array("BC", "BuildKanshokuList") _
|
||||||
|
)
|
||||||
|
|
||||||
|
Dim i As Long
|
||||||
|
For i = LBound(dropdowns) To UBound(dropdowns)
|
||||||
|
Dim col As String: col = dropdowns(i)(0)
|
||||||
|
Dim funcName As String: funcName = dropdowns(i)(1)
|
||||||
|
Dim cellValue As String: cellValue = Trim(Me.Cells(rowNum, col).Value)
|
||||||
|
If cellValue = "" Then GoTo NextDropdown
|
||||||
|
|
||||||
|
Dim key As String: key = GetCode(cellValue)
|
||||||
|
If InStr(cellValue, ":") = 0 Then GoTo NextDropdown ' Skip if not key:value format
|
||||||
|
|
||||||
|
' Get dropdown list
|
||||||
|
Dim dropdownList As String: dropdownList = Application.Run(funcName)
|
||||||
|
Dim items As Variant: items = Split(dropdownList, ",")
|
||||||
|
|
||||||
|
' Check if key exists in dropdown
|
||||||
|
Dim j As Long
|
||||||
|
For j = LBound(items) To UBound(items)
|
||||||
|
Dim item As String: item = Trim(items(j))
|
||||||
|
If GetCode(item) = key Then
|
||||||
|
' Found matching key, update with full key:value
|
||||||
|
Me.Cells(rowNum, col).Value = item
|
||||||
|
Exit For
|
||||||
End If
|
End If
|
||||||
NextCell:
|
Next j
|
||||||
Next cell
|
NextDropdown:
|
||||||
|
Next i
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
' Fill kukan info from M1 cache (key: kukan code, value: 7 elements)
|
' Fill kukan info from M1 cache (key: kukan code, value: 7 elements)
|
||||||
@@ -331,12 +386,8 @@ End Sub
|
|||||||
' triggered by c clomun cshainno input
|
' triggered by c clomun cshainno input
|
||||||
' when cshainno does not exist in o1, clear dropdownList and value
|
' when cshainno does not exist in o1, clear dropdownList and value
|
||||||
' when cshainno exist in o1, create dropdownList and value
|
' when cshainno exist in o1, create dropdownList and value
|
||||||
Private Sub CreateAddress1Dropdown(ByVal rowNum As Long, ByVal cshainno As String)
|
Private Sub BuildAddress1Dropdown(ByVal rowNum As Long, ByVal cshainno As String)
|
||||||
Dim o1Cache As Object: Set o1Cache = GetCache("O1")
|
Dim o1Cache As Object: Set o1Cache = GetCache("O1")
|
||||||
Me.Range("I" & rowNum).Validation.Delete
|
|
||||||
Me.Range("I" & rowNum).Value = ""
|
|
||||||
Me.Range("J" & rowNum).Validation.Delete
|
|
||||||
Me.Range("J" & rowNum).Value = ""
|
|
||||||
' Build dropdown list from O1 cache: get all E values for the C
|
' Build dropdown list from O1 cache: get all E values for the C
|
||||||
Dim dropdownList As String
|
Dim dropdownList As String
|
||||||
If o1Cache.Exists(cshainno) Then
|
If o1Cache.Exists(cshainno) Then
|
||||||
@@ -365,14 +416,35 @@ Private Sub CreateAddress1Dropdown(ByVal rowNum As Long, ByVal cshainno As Strin
|
|||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Sub ReFillAddress1(ByVal rowNum As Long, ByVal cshainno As String)
|
||||||
|
Dim o1Cache As Object: Set o1Cache = GetCache("O1")
|
||||||
|
If Not o1Cache.Exists(cshainno) Then
|
||||||
|
Me.Cells(rowNum, ADDRESS1_COL).Value = ""
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim innerDict As Object: Set innerDict = o1Cache(cshainno)
|
||||||
|
If innerDict.Count = 1 Then
|
||||||
|
' Auto-fill if only one key exists
|
||||||
|
Dim keys As Variant: keys = innerDict.Keys
|
||||||
|
Me.Cells(rowNum, ADDRESS1_COL).Value = keys(0)
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim originalValue As String: originalValue = Trim(Me.Cells(rowNum, ADDRESS1_COL).Value)
|
||||||
|
If originalValue = "" Then Exit Sub
|
||||||
|
|
||||||
|
' Clear if value not found in O1 cache keys
|
||||||
|
If Not innerDict.Exists(originalValue) Then
|
||||||
|
Me.Cells(rowNum, ADDRESS1_COL).Value = ""
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
' triggered by address1 select O1 cache
|
' triggered by address1 select O1 cache
|
||||||
Private Sub CreateAddress2Dropdown(ByVal rowNum As Long)
|
Private Sub BuildAddress2Dropdown(ByVal rowNum As Long, ByVal cshainno As String)
|
||||||
' Clear address2 contents
|
' Clear address2 contents
|
||||||
Me.Range(ADDRESS2_COL & rowNum).Validation.Delete
|
|
||||||
Me.Range(ADDRESS2_COL & rowNum).Value = ""
|
|
||||||
' obtain cshainno, address1, o1Cache
|
' obtain cshainno, address1, o1Cache
|
||||||
Dim o1Cache As Object: Set o1Cache = GetCache("O1")
|
Dim o1Cache As Object: Set o1Cache = GetCache("O1")
|
||||||
Dim cshainno As String: cshainno = Trim(Me.Cells(rowNum, CSHAINNO_COL).Value)
|
|
||||||
Dim address1 As String: address1 = Trim(Me.Cells(rowNum, ADDRESS1_COL).Value)
|
Dim address1 As String: address1 = Trim(Me.Cells(rowNum, ADDRESS1_COL).Value)
|
||||||
If cshainno = "" OR address1 = "" Then
|
If cshainno = "" OR address1 = "" Then
|
||||||
Exit Sub
|
Exit Sub
|
||||||
@@ -412,6 +484,35 @@ Private Sub CreateAddress2Dropdown(ByVal rowNum As Long)
|
|||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Sub ReFillAddress2(ByVal rowNum As Long, ByVal cshainno As String)
|
||||||
|
Dim address1 As String: address1 = Trim(Me.Cells(rowNum, ADDRESS1_COL).Value)
|
||||||
|
If address1 = "" Then
|
||||||
|
Me.Cells(rowNum, ADDRESS2_COL).Value = ""
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim o1Cache As Object: Set o1Cache = GetCache("O1")
|
||||||
|
If Not o1Cache.Exists(cshainno) Then
|
||||||
|
Me.Cells(rowNum, ADDRESS2_COL).Value = ""
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim innerDict As Object: Set innerDict = o1Cache(cshainno)
|
||||||
|
If Not innerDict.Exists(address1) Then
|
||||||
|
Me.Cells(rowNum, ADDRESS2_COL).Value = ""
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim addr2Dict As Object: Set addr2Dict = innerDict(address1)
|
||||||
|
If addr2Dict.Count = 1 Then
|
||||||
|
Dim keys As Variant: keys = addr2Dict.Keys
|
||||||
|
Me.Cells(rowNum, ADDRESS2_COL).Value = keys(0)
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
Me.Cells(rowNum, ADDRESS2_COL).Value = ""
|
||||||
|
End Sub
|
||||||
|
|
||||||
' Create station from dropdown from M1_KukanD cache
|
' Create station from dropdown from M1_KukanD cache
|
||||||
Private Sub CreateFromStationDropdown(ByVal rowNum As Long, ByVal transportCol As Long, ByVal stationCol As Long)
|
Private Sub CreateFromStationDropdown(ByVal rowNum As Long, ByVal transportCol As Long, ByVal stationCol As Long)
|
||||||
Dim m1KukanDCache As Object: Set m1KukanDCache = GetCache("M1KukanDCache")
|
Dim m1KukanDCache As Object: Set m1KukanDCache = GetCache("M1KukanDCache")
|
||||||
|
|||||||
@@ -230,15 +230,33 @@ Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As
|
|||||||
Next emptyCol
|
Next emptyCol
|
||||||
|
|
||||||
' check Duplicate
|
' check Duplicate
|
||||||
Dim i As Long
|
Dim sikyuKikan As String: sikyuKikan = Trim(ws.Range("N" & rowNum).Value)
|
||||||
For i = 7 To rowNum - 1
|
Dim hasError As Boolean: hasError = False
|
||||||
If Trim(ws.Cells(i, "C").Value) = cValue And Trim(ws.Cells(i, "I").Value) = kenshuKbn And Trim(ws.Cells(i, "J").Value) = code Then
|
Dim otherValueC As String, otherValueI As String, otherValueJ As String, otherValueN As String
|
||||||
errorCell.Value = GetErrorMsg("E013", i, code)
|
Dim otherRow As Long
|
||||||
|
For otherRow = 7 To rowNum - 1
|
||||||
|
otherValueC = Trim(ws.Cells(otherRow, "C").Value)
|
||||||
|
otherValueI = Trim(ws.Cells(otherRow, "I").Value)
|
||||||
|
otherValueJ = Trim(ws.Cells(otherRow, "J").Value)
|
||||||
|
otherValueN = Trim(ws.Cells(otherRow, "N").Value)
|
||||||
|
If kenshuKbn = "1" Then
|
||||||
|
If otherValueC = cValue And otherValueI = kenshuKbn And otherValueJ = code And otherValueN = sikyuKikan Then
|
||||||
|
hasError = True
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
If otherValueC = cValue And otherValueI = kenshuKbn And otherValueJ = code Then
|
||||||
|
hasError = True
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
|
||||||
|
If hasError = True Then
|
||||||
|
errorCell.Value = GetErrorMsg("E013", otherRow, code)
|
||||||
ws.Cells(rowNum, "C").Interior.Color = RGB(255, 0, 0)
|
ws.Cells(rowNum, "C").Interior.Color = RGB(255, 0, 0)
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
Next i
|
Next otherRow
|
||||||
|
|
||||||
|
' validate passed, clear error cell and setup backcolor
|
||||||
errorCell.ClearContents
|
errorCell.ClearContents
|
||||||
Application.EnableEvents = False
|
Application.EnableEvents = False
|
||||||
Call ChangeBackColor(rowNum)
|
Call ChangeBackColor(rowNum)
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user