计算列值在飞行中并将结果放入另一列 [英] Calculate column values On the Fly and put result in another column
问题描述
我有一个excel,它是从一个应用程序下载的,其中有几列。我的两个列需要是只读类型,这些列的数据应根据相关列的计算动态填充。
例如说我输入值"2"。在列"A"中和值"3"在列B中,然后列C'应显示"5"的值。无论何时填写A
和B的值,此计算必须在C列中即时完成。
在excel中实现相同的任何建议或指导,使用宏(或数据验证,如果需要)。
在此先感谢。
您好
Siddy Boy ,
你曾提到过,"例如我输入值"2"。在列"A"中和值"3"在列B中,然后列C'应显示"5"的值。只要为A和B填写值,就必须在列
C的运行中进行此计算。"
尝试参考下面的示例。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim num1,num2 As Double
If Target.Column = 2 Then
num1 = Target.Value
num2 = Target.Offset(0,-1).Value
Target.Offset(0,1).Value = num1 + num2
End if
End Sub
输出:
问候
Deepak
I have a excel, which is downloaded from an application, wherein it has few columns. Two of my columns need to be read-only types, and the data for these columns should be filled on the fly based on the calculations of the concerned columns.
Say for e.g. I enter value "2" in column "A" and value "3" in column B, then the column C should show the value of "5". This calculation has to be done on the fly for Column C, whenever values are filled for A and B.
Any suggestions or guidance to achieve the same in excel, either using macros (or data validations, if required).
Thanks In Advance.
Hi Siddy Boy,
You had mentioned that,"e.g. I enter value "2" in column "A" and value "3" in column B, then the column C should show the value of "5". This calculation has to be done on the fly for Column C, whenever values are filled for A and B."
Try to refer example below.
Private Sub Worksheet_Change(ByVal Target As Range) Dim num1, num2 As Double If Target.Column = 2 Then num1 = Target.Value num2 = Target.Offset(0, -1).Value Target.Offset(0, 1).Value = num1 + num2 End If End SubOutput:
Regards
Deepak
这篇关于计算列值在飞行中并将结果放入另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!