edit T1 T2 T3

This commit is contained in:
updsv7
2026-04-21 21:05:37 +09:00
parent 167aa48929
commit 5bb92f89c4
3 changed files with 95 additions and 1 deletions

View File

@@ -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

View File

@@ -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)