Excel VBA lastrow&currentrow,如果find数据或添加新行,将数据添加到行

我有一个Excel表格,我使用,它拥有3个工作表 – 表单,数据和条目。 基本上当你用button调用一个新的表格时,它会在条目表格(范围“A”)中查找lastrow,并添加1,这就是你的新表单ID。 有多个用户使用这个表单,我已经设置它在表单填充之前也添加在条目表中的数字,以便保留它,以便下一个用户不能重复。

这是我陷入困境的地方。 我希望有currentrowfind该工作表ID并粘贴在该行的数据,但我有的代码只是添加一个新的行。

这是它的样子。

Sub Submit() Dim rng1 As Range Dim rng2 As Range Dim multiplerange As Range Dim currentrow As Long Dim sheetid As String Set rng1 = Range("M1,M2,B2,F6,B7,B8,B9,B11,D11,B13,D13,I6,M6,I7,I8,I9,I11,K11,I13,K13,B15,B18,B22,E22,B23,B24,B26,E26,I22,J22,M22,K24,M24,I24,I26,K26,M26,B29,E29,B30,B31,B33,E33,I29,J29,M29,K31,M31,I31,I33,K33,M33,B36,E36,B37,B38,B40,E40,I36,J36,M36,K38,M38,I38,I40,K40,M40") Set rng2 = Range("G2") Set multiplerange = Union(rng1, rng2) Dim WSEntries As Worksheet Dim WSForm As Worksheet Set WSEntries = Sheets("Entries") Set WSForm = Sheets("Form") sheetid = WSForm.Range("M1").Text Dim lastrow As Integer lastrow = WSEntries.Cells(Rows.Count, "A").End(xlUp).Row For currentrow = 3 To lastrow If Cells(currentrow, 1) = sheetid Then Dim i As Integer i = 1 For Each c In multiplerange WSEntries.Cells(currentrow + 1, i) = c i = i + 1 Next Else i = 1 For Each c In multiplerange WSEntries.Cells(lastrow + 1, i) = c i = i + 1 Next End If Next End Sub 

任何帮助将是伟大的。 谢谢

编辑:我也没有添加所有我声明的项目,但这是脚本的另一部分。 我有其他的工作,只是我有问题的粘贴部分

得到它的工作! 切换到Range方法

 lastrow = WSEntries.Cells(Rows.Count, "A").End(xlUp).Row For currentrow = 3 To lastrow If WSEntries.Range("A" & currentrow) = sheetid Then Dim i As Integer i = 1 For Each c In multiplerange WSEntries.Cells(currentrow, i) = c i = i + 1