diff --git a/src/module/Common_Global_Cache.bas b/src/module/Common_Global_Cache.bas index bca43cd..833f813 100644 --- a/src/module/Common_Global_Cache.bas +++ b/src/module/Common_Global_Cache.bas @@ -265,7 +265,7 @@ Private Sub RefreshT2Cache() Set t2Cache = Nothing On Error GoTo RefreshError - Set t2Cache = LoadLookup("T2", keyCol:=3, valueCols:=Array(4), startRow:=7) + Set t2Cache = LoadLookup("T2", keyCol:=3, valueCols:=Array(4, 6, 8, 9, 10, 11, 12, 13), startRow:=7) On Error GoTo 0 If t2Cache Is Nothing Or t2Cache.Count = 0 Then diff --git a/src/sheet/M2.cls b/src/sheet/M2.cls index 63deae3..335c404 100644 --- a/src/sheet/M2.cls +++ b/src/sheet/M2.cls @@ -19,6 +19,100 @@ Private Sub Worksheet_Change(ByVal Target As Range) End If Next End If + + ' === Create J dropdown when I column changes === + If Target.Column = 9 And Target.Row >= 7 Then + Dim cellI As Range + For Each cellI In Target + Call CreateJDropdown(cellI.Row) + Next + End If + + ' === Fill K column when J column changes === + If Target.Column = 10 And Target.Row >= 7 Then + Dim cellJ As Range + For Each cellJ In Target + Call FillKFromJ(cellJ.Row) + Next + End If +End Sub + +Private Sub FillKFromJ(ByVal rowNum As Long) + Dim iValue As String: iValue = Trim(Me.Range("I" & rowNum).Value) + Dim jValue As String: jValue = Trim(Me.Range("J" & rowNum).Value) + + If jValue = "" Then + Me.Range("K" & rowNum).ClearContents + Exit Sub + End If + + ' Get cache based on I column value + Dim cache As Object + Select Case iValue + Case "1" + Set cache = GetT1Cache() + Case "2" + Set cache = GetT2Cache() + Case "3" + Set cache = GetT3Cache() + Case Else + Exit Sub + End Select + + If cache Is Nothing Then Exit Sub + + ' Check if J value exists in cache + If cache.Exists(jValue) Then + Dim cacheVal As Variant: cacheVal = cache(jValue) + ' K column = value (第4列) + Me.Range("K" & rowNum).Value = Trim(cacheVal(0)) + End If + + ' TODO: Add other settings for I=2 and I=3 + +End Sub + +Private Sub CreateJDropdown(ByVal rowNum As Long) + Dim iValue As String: iValue = Trim(Me.Range("I" & rowNum).Value) + Dim targetCell As Range: Set targetCell = Me.Range("J" & rowNum) + + ' Clear existing validation + targetCell.Validation.Delete + targetCell.ClearContents + + ' Get cache based on I column value + Dim cache As Object + Select Case iValue + Case "1" + Set cache = GetT1Cache() + Case "2" + Set cache = GetT2Cache() + Case "3" + Set cache = GetT3Cache() + Case Else + Exit Sub + End Select + + If cache Is Nothing Then Exit Sub + + ' Build dropdown list from cache + Dim dropdownList As String: dropdownList = "" + Dim key As Variant + For Each key In cache.Keys + If dropdownList = "" Then + dropdownList = key + Else + dropdownList = dropdownList & "," & key + End If + Next key + + If dropdownList <> "" Then + With targetCell.Validation + .Add Type:=xlValidateList, Formula1:=dropdownList + .IgnoreBlank = True + .InCellDropdown = True + End With + End If End Sub Private Sub FillFromM1(ByVal rowNum As Long) diff --git a/通勤手当テンプレート_案.xlsm b/通勤手当テンプレート_案.xlsm index 516a09a..c7a60f9 100644 Binary files a/通勤手当テンプレート_案.xlsm and b/通勤手当テンプレート_案.xlsm differ