【问题标题】:Change a cell value when validation updates验证更新时更改单元格值
【发布时间】:2016-07-25 11:10:10
【问题描述】:

我无法在单元格更改时更改单元格值。基本上当验证Range("F112")发生变化并且值为<> "Lease"然后Range"("F108")需要更改为0

到目前为止,我想出了:

模块

Sub SetLeaseToZero()

Dim Settlement As Integer
Settlement = Sheets("HV.Select Pricing").Range("F108")

If Sheets("HV.Select Pricing").Range("F112") <> "Lease" Then
Settlement = 0
Else
End If

End Sub

换张

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Me.Range("F112")) Is Nothing Then
SetLeaseToZero
End If

End Sub

提前致谢

【问题讨论】:

  • 首先你需要添加Call SetLeaseToZero 这样它就会调用你的子
  • @ShaiRado 这不正确。 SetLeaseToZero 足以运行该子程序。自己试试吧。

标签: excel auto-update vba


【解决方案1】:

您需要设置结算对象才能更改该值。如图所示调整你的模块代码:

Sub SetLeaseToZero()

Dim Settlement As Range
Set Settlement = Sheets("HV.Select Pricing").Range("F108")

If Sheets("HV.Select Pricing").Range("F112").Value <> "Lease" Then
    Settlement.Value = 0
End If

End Sub

请注意,.Value 调用在技术上不是必需的,但它们有助于澄清代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多