是否可以在包含公式的单元格中键入内容而不删除公式对该单元格的作用?

发布于 2025-01-14 08:39:41 字数 143 浏览 3 评论 0原文

是否可以在已有公式的单元格中输入内容?

我将在这里更详细地讨论

相关单元格中的公式,当另一个工作表中输入了值时,该公式将与该单元格中的结果相匹配。

是否可以在此单元格中输入文本但保留公式,以便当单元格为空时公式保留并仍然显示结果?

Is it possible to be able to type in a cell that already has a formula in it?

I'll go into a bit more detail here

The cell in question has a formula in it that when another sheet has a value typed in it is matched with the result into the said cell.

Is it possible type in this cell with text but keeping the formula so when the cell is blank the formula stays and still displays the result?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水水月牙 2025-01-21 08:39:41

您无法完全按照您的要求进行操作,但您可以使用一些 VBA 代码,在每次清除单元格时将公式替换回单元格中。

您可以使用 Worksheet_Change 事件 (MS 文档页面)。每次更改下面代码所在的工作表(假设为 Sheet1)时,它都会检查任何更改的单元格是否在 C1:C10 范围内,并且,如果它们为空,请输入引用该单元格中 sheet2 中相同单元格地址的公式。

如果您想使用它,您将需要更改代码,以便它影响您想要的单元格,并提供您实际正在寻找的公式(因为您没有说出其中任何一个是什么)。

Private Sub Worksheet_Change(ByVal Target As Range)

    Set Target = Intersect(Target, Sheet1.Range("C1:C10")) 'change the range address here to control which cells are affected by the change
    If Target Is Nothing Then Exit Sub

    For Each cll In Target
        If IsEmpty(cll) Then
            cll.Formula = "=Sheet2!" & cll.Address 'change this line 
        End If
    Next cll

End Sub

You can't do exactly what you are asking for, but you can have some VBA code that will replace the formula back in a cell every time it is cleared.

you would do this using the Worksheet_Change event (MS Docs page here). Every time the worksheet the code below is in (assumed to be Sheet1) is changed, it will check if any of the changed cells are in the range C1:C10 and, if they are empty, enter a formula that refers to the same cell address in sheet2 in that cell.

If you want to use this, you will need to alter the code so it affects the cells you want it to, and provides the formula you are actually looking for (as you dont say what either of those are).

Private Sub Worksheet_Change(ByVal Target As Range)

    Set Target = Intersect(Target, Sheet1.Range("C1:C10")) 'change the range address here to control which cells are affected by the change
    If Target Is Nothing Then Exit Sub

    For Each cll In Target
        If IsEmpty(cll) Then
            cll.Formula = "=Sheet2!" & cll.Address 'change this line 
        End If
    Next cll

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文