以相似的模式将多个功能捆绑在一起 excel

tying multiple functions together in a similar pattern excel

我正在 excel 做预算之类的。我想突出显示一堆并排的行,然后说 "for each of these rows on the left, make the row on the right equal to 12 * the left row",左边是月成本,右边是年。

我想换右边就换左边,换左边就换右边。我还希望我的其他功能(这些行的垂直总和)不会受到损坏。

这是否可行,我可以垂直突出显示 20 行或更多行并告诉它模式?谢谢

我知道你说你不知道VBA,因为如果你知道它很简单,我想我会帮助你。

将其放在预算信息所在的 sheet 的 VBE 中的工作sheet 模块中。 Here 是关于如何将代码放入 worksheet 模块的教程。

您可能唯一需要调整的是范围引用(F3:F23 和 G3:G23)到您的实际单元格引用。

Private Sub Worksheet_Change(ByVal Target As Range)

'if monthly data changes
If Not Intersect(Target, Me.Range("F3:F23")) Is Nothing Then

    Application.EnableEvents = False
    Target.Offset(, 1).Value = Target * 12
    Application.EnableEvents = True

End If

'if yearly data changes
If Not Intersect(Target, Me.Range("G3:G23")) Is Nothing Then

    Application.EnableEvents = False
    Target.Offset(, -1).Value = Target / 12
    Application.EnableEvents = True

End If

End Sub