edit T1 T2 T3
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user