這樣的事情(去工作表代碼模塊中)
Private Sub Worksheet_Change(ByVal Target As Range)
Const VAL_TRIPLE As String = "Triple"
Const VAL_DOUBLE As String = "Double"
Dim rng As Range, cost
On Error GoTo haveError
Set rng = Target.Cells(1)
If rng.Column = 1 And rng.Row > 1 Then
DoEvents 'run the cost lookup...
cost = rng.EntireRow.Cells(4).Value
With rng
If .Value = VAL_DOUBLE Or .Value = VAL_TRIPLE Then
Application.EnableEvents = False
.Offset(1, 0).Insert
.Offset(1, 0).Value = .Value
If IsNumeric(cost) Then
.Offset(1, 3).Value = cost * IIf(.Value = VAL_TRIPLE, 2, 1)
End If
.Value = "replacement" 'how to know what goes here?
.Offset(1, 1).Value = .Offset(0, 1).Value
.Offset(1, 2).Value = .Offset(0, 2).Value
Application.EnableEvents = True
End If
End With
End If
Exit Sub
haveError:
Application.EnableEvents = True
End Sub
將如何使從下拉列表中選擇「超過合同」? –
下拉式選項包括合同記帳和超出合同的選項(即合同= 1000,超額= 2000,3000)......您只能將合同金額翻一番或三倍。如果用戶選擇2000,我希望初始選擇的選項(從下拉菜單)變爲1000,下面一行自動填充到1000.希望這是有道理的。謝謝。 –
因此,如果他們選擇「三重」選項,那麼會發生什麼?會插入兩個額外的行嗎? –