我对宏非常陌生,需要针对我的要求的解决方案。 如果值匹配,我想比较同一工作簿的2个不同工作表中的2列,然后将数据从sheet1值(第3,4和5列)复制并粘贴到sheet2(第3,4,5列)
当前,我的代码无法获得结果,请帮助
Sub oldtonew()
Dim Oldoutcome(1000) As Variant
Dim newoutcome(1000) As Variant
Dim I As Integer
Dim PA1(1000) As String
Dim PA2(1000) As String
Dim PA3(1000) As String
Dim AR(1000) As Variant
Searchrow = 2
Sheets("old").Select
newoutcome(Searchrow) = "Architectural Model"
'ActiveSheet.Range("S" & Searchrow).Value
Do Until ActiveSheet.Range("AK" & Searchrow) = ""
Oldoutcome(Searchrow) = ActiveSheet.Range("AK" & Searchrow).Value
AR(Searchrow) = ActiveSheet.Range("X" & Searchrow).Value
PA1(Searchrow) = ActiveSheet.Range("AR" & Searchrow).Value
PA2(Searchrow) = ActiveSheet.Range("AS" & Searchrow).Value
PA3(Searchrow) = ActiveSheet.Range("AT" & Searchrow).Value
If InStr(Oldoutcome(Searchrow), newoutcome(Searchrow)) > 1 Then
ActiveSheet.Range("Y" & Searchrow).Value = AR(Searchrow)
ActiveSheet.Range("Z" & Searchrow).Value = PA1(Searchrow)
ActiveSheet.Range("AA" & Searchrow).Value = PA2(Searchrow)
ActiveSheet.Range("AB" & Searchrow).Value = PA3(Searchrow)
End If
Searchrow = Searchrow + 1
Loop
Sheets("Assessment").Select
Do Until ActiveSheet.Range("S" & Searchrow) = ""
ActiveSheet.Range("Y" & Searchrow).Value = AR(Index)
ActiveSheet.Range("Z" & Searchrow).Value = PA1(Index)
ActiveSheet.Range("AA" & Searchrow).Value = PA2(Index)
ActiveSheet.Range("AB" & Searchrow).Value = PA3(Index)
End If
Searchrow = Searchrow + 1
Loop
End Sub