how do I write macro to copy the value of a cell to another if va.

G

Guest

How do I write a macro to copy the value of cell A1, B1, C1 of sheet1 to
E1,F1 & G1 of sheet2 respectively if the value of cell A1 of sheet2 is equal
to the value of cell B1of sheet1?
 
N

Nigel

If you want to run it manually (or from another macro) then use this.....

Sub copy()
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")

If sh2.Range("A1").Value = sh1.Range("B1").Value Then
sh2.Range("E1").Value = sh1.Range("A1").Value
sh2.Range("F1").Value = sh1.Range("B1").Value
sh2.Range("G1").Value = sh1.Range("C1").Value
End If
End Sub

If you need to make it to sense the change in the cells that set the
condition then you need to trap worksheet events - repost here for support.
 
G

Guest

This is a good example of the value of the discussion group. If the data is
updated frequently, then Bob Phillips’ solution is good because “the resultâ€
responds automatically to the updates. If “the result†needs to be exported,
then Nigel’s solution is good because it produces a snapshot with no links to
remove.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top