View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
[email protected] Internetdomainowner@hotmail.com is offline
external usenet poster
 
Posts: 32
Default Help to code Macro to Copy fron one sheet and paste in othersheet

On Jul 24, 4:11*pm, kay wrote:
Hi
I have tow excel sheets.- sheet1 and sheet2
in sheet2 i have all columns from sheet1 + *additional columns.
in sheet1 i have unique Action# column which does not have dublicate data..
and that ACtion# is in sheet2 (as i have copied Sheet1 data).

So what i want when some one adds or update data of sheet1,
i want to run a macro which adds new data(rows) into sheet2 and updates data
as well (update means- if someone updates the data in sheet1, it should
update those data in sheet2 when you run a macro)

So need help to code macro which adds data in sheet2 and if data is there
then update it.

I appreciate for any help.

Thanks!


Suppose you could always Vlookup the ActiveCell.value and have a macro
to do the following...

Right click on the sheet1 tab and goto View Code
Sheet


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False 'Turns off the flicker
ActiveCell.Offset(0, 1).Value = "=IF(ISNA(VLOOKUP(" &
ActiveCell.Offset(0, -1).Address & ", Sheet2!A:A, 1, FALSE))", "",
VLOOKUP(" & ActiveCell.Offset(0, -1).Address & ", Sheet2!A:A, 1,
FALSE))"
ActiveCell.Offset(0, 1).Select

If Len(ActiveCell.Value) = 0 Then
Sheets("Sheet2").Select
'DoYourDesiredActionGoesHere
Sheets("Sheet1").Select
End If

ActiveCell.Offset(0, 1).Value = ""
ActiveCell.Offset(1, 0).Select 'Just jumps down to the next row

End Sub

The basic idea is a VLOOKUP statement will return a value if it's
found in a specific range of data. If it's found it means that the
data is there and nothing has to change. If the VLOOKUP comes back as
nothing you can get the code to do what you need it to. There are
seriously better ways of doing what your doing but they are far more
complicated then what I'm showing here. I hope this helps points in
you the right direction.