简体   繁体   中英

Calculate a formula from one cell in a sheet and paste the result in another different cell from another different sheet

I know how to code the formula but not how to make them move from a sheet to another

Basically the idea is that user types data in one sheet, and then they get the result of the formula in another sheet from the same excel

Assuming that the formula =C6/C9 in placed in cell C10 .

If you want to use VBA then you can place the following code under the Sheet that has the formulas and specify which sheet you want the result to go into as below:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet: Set ws = Sheets("Sheet2")
'declare and set the worksheet the data is to be copied into, amend the sheet name as required
If Target.Address = "$C$6" Or Target.Address = "$C$9" Then 'if anything changes in C6 or C9 in this sheet
    ws.Range("E5").Value = Target.Parent.Range("C10") 'copy the value from cell C10 in this sheet to Sheet2 in cell E5
End If
End Sub

You could also do this without VBA, in Sheet2 in cell E5 you could also enter the following and would achieve the same result: =Sheet1!C10

Or you could even enter in Sheet2 E5 the actual formula you want to calculate as:

=Sheet1!C6/Sheet1!C9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM