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

时间:2015-07-10 15:26:25

标签: excel vba excel-vba

对象不支持此属性或方法。仅发生在此代码中的.Paste部分。请帮忙,因为我很困惑。我试图简单地简化代码,只需选择单元格,复制单元格,选择目标和粘贴。这里缺少一些东西......

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

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:1)

你无法做Selection.Paste(正如你刚才所说)。如果您在工作表上致电Paste,它会粘贴到您的选择中,请尝试使用

ActiveSheet.Paste

相关问题