0
我得到了一些excel表,用户必须在sheet2上插入数据列表。 然后用户点击一个按钮,sheet1基于sheet2中的数据插入进行更新。查找记录和更新
此代码将查找sheet2中的数据是否缺少,然后正确插入数据。 我还需要有现有的记录opdated。 工作表1上的现有数据已添加带有注释的manuel列,这些注释在数据更新时不应删除。
在Sheet1数据位于从C到N型柱 - 键位于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
该代码只搜索关键字,如果不存在,则会添加一个包含数据的新行。表1中的数据然后排序,这就是为什么我需要帮助。我如何找到并找到需要更新的字段? – user1870816
你能提供一个你的工作簿的例子吗? (图片/样本数据或文件等)。除非表2中的内容真的不同,否则它应该是第一个的近似副本,如果块 – NickSlash
请参阅下面的注释 – user1870816