Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$4" Or Target.Address = "$F$4" Then
Select Case Range("E4").Value
Case "B4"
Select Case Range("F4").Value
Case "C4"
Range("F5").Value = Range("F9").Value
Case "C5"
Range("F5").Value = Range("F10").Value
Case "C6"
Range("F5").Value = Range("F11").Value
End Select
Case "B5"
Select Case Range("F4").Value
Case "C4"
Range("F5").Value = Range("F12").Value
Case "C5"
Range("F5").Value = Range("F13").Value
Case "C6"
Range("F5").Value = Range("F14").Value
End Select
End Select
End If
End Sub
試一下看看作者: bhsm 時間: 2023-4-9 10:48
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$4" Or Target.Address = "$F$4" Then
If Range("E4").Value = "B4" Then
Select Case Range("F4").Value
Case "C4"
Range("F5").Value = Range("F9").Value
Case "C5"
Range("F5").Value = Range("F10").Value
Case "C6"
Range("F5").Value = Range("F11").Value
End Select
ElseIf Range("E4").Value = "B5" Then
Select Case Range("F4").Value
Case "C4"
Range("F5").Value = Range("F12").Value
Case "C5"
Range("F5").Value = Range("F13").Value
Case "C6"
Range("F5").Value = Range("F14").Value
End Select
End If
End If
End Sub
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address = "$E$4" Or .Address = "$F$4" Then
Dim Y, i%, j%, T$, S
Set Y = CreateObject("Scripting.Dictionary")
For i = 4 To 5
For j = 4 To 6
T = Cells(i, 2) & "|" & Cells(j, 3)
S = Cells(i + j + (3 ^ (i - 4)), 6)
If Not Y.Exists(T) Then
Y(T) = S
ElseIf Y(T) <> S Then
Y(T) = "無法辨識"
End If
Next
Next
[F5] = Y([E4] & "|" & [F4])
If [F5] = "無法辨識" Then MsgBox "排列組合子重複無法辨識"
Set Y = Nothing
End If
End With
End Sub作者: bhsm 時間: 2023-4-10 10:22
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address = "$E$4" Or .Address = "$F$4" Then
Dim Y, i%, j%, T$, S, Brr
Set Y = CreateObject("Scripting.Dictionary")
Brr = [F9].Resize(6, 1)
For i = 4 To 5
For j = 4 To 6
T = Cells(i, 2) & "|" & Cells(j, 3)
S = Val(Cells(i, 2)) + Val(Cells(j, 3))
N = N + 1: Y(T) = S
If T = [E4] & "|" & [F4] Then Brr(N, 1) = Y(T)
Next
Next
[F9].Resize(6, 1) = Brr
Set Y = Nothing: Erase Brr
End If
End With
End Sub作者: bhsm 時間: 2023-4-10 15:56
謝謝前輩,以下心得註解請參考
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'↑當使用者或外部連結變更工作表中的儲存格時會發生此事件
With Target
'↑以下是關於觸發事件的程序
If .Address = "$E$4" Or .Address = "$F$4" Then
'↑如果觸發儲存格是[E4] 或[F4]的位址
Dim Y, S, Brr, i%, j%, T$, N&
'↑宣告變數:(Y,S,Brr)是通用型變數,(i,j)是短整數,T是字串變數
'N是長整數
Set Y = CreateObject("Scripting.Dictionary")
'↑令Y這通用型變數是 字典
Brr = [F9].Resize(6, 1)
'↑令Brr這通用型變數是 二維陣列,以[F9]向下擴展6格的儲存格值帶入
For i = 4 To 5
'↑設順迴圈!i從4到 5
For j = 4 To 6
'↑設順迴圈!j從4到 6
T = Cells(i, 2) & "|" & Cells(j, 3)
'↑令T這字串變數是 i迴圈列B欄儲存格值連接 "|",
'再連接 j迴圈列C欄儲存格值之後的新字串
S = Val(Cells(i, 2)) + Val(Cells(j, 3))
'↑令S這通用型變數是 i迴圈列B欄儲存格值轉化為數字值,
'加上j迴圈列C欄儲存格值轉化為數字值之後的新數值
N = N + 1: Y(T) = S
'↑令N這長整數變數 累加1
'令以T變數為key,item是S變數,納入Y字典
If T = [E4] & "|" & [F4] Then Brr(N, 1) = Y(T)
'↑如果T變數(字串)同
'[E4]儲存格值連接"|" 再連接[F4]儲存格值組成的新字串??
'就令N變數列第1欄Brr陣列值是 以T變數查Y字典的item值
Next
Next
[F9].Resize(6, 1) = Brr
'↑[F9]向下擴展6格的儲存格值以 Brr陣列值帶入
Set Y = Nothing: Erase Brr
'↑釋放變數
End If
End With
End Sub作者: bhsm 時間: 2023-4-10 16:52
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address = "$F$3" Or .Address = "$H$3" Then
If [G7] = "" Then
[G7] = [G4]
Else
[G65536].End(3).Item(2) = [G4]
End If
End If
End With
End Sub作者: bhsm 時間: 2023-4-11 18:16
Private Sub Worksheet_Change(ByVal Target As Range)
'↑當使用者或外部連結變更工作表中的儲存格時會發生此事件
With Target
'↑以下是關於觸發事件的程序
If .Address = "$F$3" Or .Address = "$H$3" Then
'↑如果觸發儲存格是[F3] 或[H3]的位址
If [G7] = "" Then
'↑如果[G7]儲存格值是空字元
[G7] = [G4]
'↑令[G7]儲存格值是 [G4]儲存格值
Else
[G65536].End(3).Item(2) = [G4]
'↑否則令G欄最後一個有內容儲存格的下方一格值是 [G4]儲存格值
End If
End If
End With
End Sub作者: bhsm 時間: 2023-4-12 21:38
利用 index 值填充//
Private Sub Worksheet_Change(ByVal Target As Range)
Dim j%, k%
With Target
If .Address <> "$E$4" And .Address <> "$F$4" Then Exit Sub
j = Abs(([e4] = [b4]) + ([e4] = [b5]) * 4)
k = Abs(([f4] = [c4]) + ([f4] = [c5]) * 2 + ([f4] = [c6]) * 3)
If j * k Then [f9].Cells(j + k - 1) = [f5]
End With
End Sub作者: bhsm 時間: 2023-4-22 10:49