Excel 2003:提取计算结果

发布于 2025-01-08 05:12:34 字数 262 浏览 0 评论 0原文

我想知道是否有一种方法可以链接单元格,使其永久保存计算结果,这样即使计算的输入发生更改,仍然保存以前的结果。

为了进一步说明,例如,当我们假设第一种情况下我的计算是 x+2=y 并且 x = 1 时。我希望能够链接一个单元格来保存结果 y=3 以及输入 x =1,即使我更改 x 的值也是如此。

一个可能的解决方案是同时使用 IF 条件和 PASTE SPECIAL 命令,但我不确定如何对其进行编程以使其自动化。有没有办法使用公式来做到这一点?或者我必须冒险进入 VBA 吗?

I would like to know if there is a way to link a cell such that it holds the results of a calculation permanently so that even when the input to the calculation is changed, the previous result is still saved.

To further illustrate, for example, when lets say my calculation is x+2=y and x = 1 in the first case. I want to be able to link a cell to save the result y=3 and also the input x =1, even when I change the value of x.

A possible solution to do use an IF condition and a PASTE SPECIAL command together, but I am not sure how to programme it such that it is automated. Is there a way to do this using formulas? Or must I venture into VBA?

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

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

发布评论

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

评论(2

胡大本事 2025-01-15 05:12:34

<块引用>
<块引用>

一个可能的解决方案是同时使用 IF 条件和 PASTE SPECIAL 命令,但我不确定如何对其进行编程以使其自动化。有没有办法使用公式来做到这一点?或者我必须冒险进入 VBA 吗?


这是一种不需要 PASTE SPECIAL 命令的方法。将代码粘贴到相关工作表代码区域。请参阅快照1。这只是一个例子。请根据您的要求进行更改。该代码的作用是,它检查用户是否输入了 X(单元格 A2)的任何值,如果用户输入了,则捕获它捕获 Y(单元格 B2)的值并将其存储在 D 列中。请参阅 快照 2。

在此处输入图像描述

快照 1

在此处输入图像描述

快照 2

这是完整的代码。不过,请注意一点。如果没有“.EnableEvents = False”或主表中没有错误处理,请勿尝试此代码。

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LastRow As Long
    
    On Error GoTo Whoa
    
    '~~> Check if any value was entered in cell A2
    If Not Intersect(Target, Range("A2")) Is Nothing Then
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
        
        '~~> Get the next available line in Col D for output
        LastRow = Range("D" & Rows.Count).End(xlUp).Row + 1
        
        '~~> Save the value
        Range("D" & LastRow).Value = Range("B2").Value
    End If
    
LetsContinue:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume LetsContinue
End Sub

HTH

希德

A possible solution to do use an IF condition and a PASTE SPECIAL command together, but I am not sure how to programme it such that it is automated. Is there a way to do this using formulas? Or must I venture into VBA?

Here is one way without the need of PASTE SPECIAL command. Paste the code in relevant Worksheet code area. Please refer to the snapshot 1. This is just an example. Please change it as per your requirements. What the code does is, it checks if the user entered any Value of X (Cell A2) and if the user did then capture it captures the value of Y(Cell B2) and stores it in Col D. Please refer to snapshot 2.

enter image description here

Snapshot 1

enter image description here

Snapshot 2

And this is the complete code. One piece of caution though. Do not try this code without the ".EnableEvents = False" or without the error handling in your main sheet.

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LastRow As Long
    
    On Error GoTo Whoa
    
    '~~> Check if any value was entered in cell A2
    If Not Intersect(Target, Range("A2")) Is Nothing Then
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
        
        '~~> Get the next available line in Col D for output
        LastRow = Range("D" & Rows.Count).End(xlUp).Row + 1
        
        '~~> Save the value
        Range("D" & LastRow).Value = Range("B2").Value
    End If
    
LetsContinue:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume LetsContinue
End Sub

HTH

Sid

感性不性感 2025-01-15 05:12:34

您可以复制单元格 y 的值并粘贴(仅值)到另一个单元格中。
右键单击->选择性粘贴 -->选择“值”

You can copy the value of cell y and paste - values only - in another cell.
Right Click -> Paste Special --> Select 'values'

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