2015-07-10 56 views
1

對象不支持此屬性或方法。僅在此代碼中的.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 

回答

1

你不能這樣做Selection.Paste(正如你剛纔看到)。如果您在紙張上稱之爲Paste,它會粘貼到您的選擇,試試這個,而不是

ActiveSheet.Paste

+0

看起來是對的。謝謝。 –

3

或者,如果你只是想複製的價值,跳過這個選擇並粘貼:

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