I got some excel sheets where user has to insert list of data on sheet2.
Then user hit a button and sheet1 is updated based on the data insertes in sheet2.
This code will find if data in sheet2 is missing in sheet and then insert the data correctly.
I also need to have existing records opdated.
Existing data on sheet1 has been added manuel columns with comments, these comments should not be deleted on data update.
Data on sheet1 is located from C to N column – key is located in J.
Dim iLast As Long
Dim iCounter As Integer
iLast = Sheets(2).Range("I" & Application.Rows.Count).End(xlUp).Row
Dim rng As Range
For iCounter = 2 To iLast
Set rng = Sheets(1).Range("J:J").Find(Sheets(2).Range("I" & iCounter).Value)
If rng Is Nothing Then
Sheets(2).Range("B" & iCounter & ":" & "M" & iCounter).Copy
Sheets(1).Range("C" & Sheets(1).Range("J" & Application.Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteAll
Range("B2").Select
'Insert mailto link
Selection.Copy
Sheets(1).Range("B" & Sheets(1).Range("J" & Application.Rows.Count).End(xlUp).Row).Select
'Range("B3").Select
ActiveSheet.Paste
ActiveSheet.Paste
Application.CutCopyMode = False
Else
'MsgBox "update existing row with new data - how to"
End If
Next iCounter
You should be able to do it in a similar way to adding a new line.
If you use xlPasteValues instead of xlPasteAll the comments in Sheet 1 should not be affected.
Assuming that your just copying the values and there’s no extra formatting or comments to be copied across.
I’m not exactly sure what your trying to achieve which makes it a little more difficult for me, but I think this is what you are trying to do?