我正在做一个项目,对VBA还是很陌生。有人可以帮助您扫描源工作表中一列中的数据并与目标工作表中的一列进行比较的代码。如果任何行的目标工作表列中都没有数据,则需要在下一个空行中填充数据,直到目标工作表列中的空行范围结束为止。
Blockquote
Sub Updatesheet()
Application.ScreenUpdating = False
Dim SourceWS As Worksheet
Set SourceWS = Workbooks("ABC.xlsm").Worksheets("Data_ COS")
Dim SourceRange As Range
Set SourceRange = SourceWS.Range("O2:O3001")
Dim TargetWS As Worksheet
Set TargetWS = Workbooks("ABC.xlsm").Worksheets("Plant Data")
Dim Targetrange As Range
Set Targetrange = TargetWS.Range("C3:C101")
Dim currentRow As Integer
Dim foundval As Range
Dim Target As Integer
Dim Data As Range
Dim currentRowValue As String
SourceWS.Activate
For Each Cell In SourceRange
If Cell.Value <> "" Then
currentRow = 3
If currentRow < 101 Then
Set foundval = TargetWS.Range("C3:C101").Find(Cell.Value, LookIn:=xlValues, LookAt:=xlWhole)
If foundval Is Nothing Then
SourceWS.Cells(Cell.Row, 15).Copy
Target = currentRow
If Target < 101 Then
currentRowValue = TargetWS.Cells(Target, 3).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
TargetWS.Cells(Target, 3).PasteSpecial
End If
currentRow = Target + 1
End If
End If
End If
End If
Next Cell
Application.ScreenUpdating = True
结束子
但是问题是从源工作表的第一行仅填充一个数据,并要求选择目标单元格并输入以粘贴。