Help to code Macro to Copy fron one sheet and paste in other sheet

K

kay

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!
 
O

Otto Moehrbach

Kay
Help us out here. Pretend that you have to do this manually (no
automation). Now come up with all the different scenarios of the possible
conditions that you might have, things like the Action# exists in sheet1 but
not in sheet 2, the Action# exists in both sheets, any other scenarios you
know about. Then give us a step-by-step of how you would handle each
scenario. Don't leave out any steps. Nobody knows what you have and what
you want like you do. HTH Otto
 
I

Internetdomainowner

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.
 

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