为什么不粘贴? 使用variables和偏移单元格引用

对象不支持这个属性或方法。 只发生在这段代码的.Paste部分。 请帮忙,因为我很困惑。 我试图尽可能简化代码来简单地select单元格,复制单元格,select目标和粘贴。 有些东西在这里丢失…

Sub AIM36DBOCompare() Dim n As Integer n = 2 Dim PasteCount As Integer Dim Value1 As String Dim Date1 As String Dim c As Range PasteCount = 41 Range("AD2:AD1000").Copy Destination:=Range("S41" & Lastrow) Do While n <= 1000 If Cells(26, n) <> 0 Then '-------------------------------------------- With Worksheets(1).Range("b2:b10000") Set c = .Find(Cells(n, 26), LookIn:=xlValues) If Not c Is Nothing Then Do Date1 = c.Offset(0, -1).Address Value1 = c.Offset(0, 3).Address If Abs(Cells(n, 25) - Range(Date1).Value) <= 10 Then Range(Value1).Select Selection.Copy Cells(PasteCount, 17).Select Selection.Paste PasteCount = PasteCount + 1 Exit Do End If Set c = .Find(Cells(n, 26).Value, LookIn:=xlValues) Loop While Not c Is Nothing End If End With '-------------------------------------------- End If If Cells(11, n) = 0 Then Exit Do End If n = n + 1 Loop End Sub 

你不能做Selection.Paste (正如你刚才观察到的)。 如果您在工作表上调用Paste ,它将粘贴到您的select,而不是尝试

ActiveSheet.Paste

或者,如果您只想复制该值,则跳过整个select并粘贴:

 Cells(PasteCount, 17).Value = Range(Value1).Value