ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help to code Macro to Copy fron one sheet and paste in other sheet (https://www.excelbanter.com/excel-programming/414570-help-code-macro-copy-fron-one-sheet-paste-other-sheet.html)

Kay

Help to code Macro to Copy fron one sheet and paste in other sheet
 
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!



Otto Moehrbach[_2_]

Help to code Macro to Copy fron one sheet and paste in other sheet
 
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
"kay" wrote in message
...
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!





[email protected]

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.

Kay

Help to code Macro to Copy fron one sheet and paste in other s
 
Thanks to both of you.
this comments will help me.


" wrote:

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.



All times are GMT +1. The time now is 06:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com