0

I need to make a macro that paste data, when i record the macro i have the same problem every time. I hope someone can help me with my problem.

Every time i debug i get the same problem with this function:

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

Range("AP5:AP43").Select
Selection.Clear
Range("AP5").Select
ActiveSheet.ListObjects("Table11").Range.AutoFilter Field:=4, Criteria1:="IT"

Range("C5:C51").Select
Selection.Copy
ActiveSheet.ListObjects("Table11").Range.AutoFilter Field:=4
Range("AP5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks 
    :=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Range("Table9[#All]").RemoveDuplicates Columns:=1, Header:= _
    xlYes
Range("Table9[Forecast på aktiviteter]").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent6
    .TintAndShade = 0.599993896298105
    .PatternTintAndShade = 0
End With
Range("AS29").Select

End Sub
JvdV
  • 70,606
  • 8
  • 39
  • 70
  • 1
    Tip: have a look at [how to avoid using .Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). And specify your problem. You say you get a problem, but neither where or what problem. – JvdV Jun 21 '19 at 11:22
  • The problem is: Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks :=False, Transpose:=False – mathias täck Jun 21 '19 at 11:27
  • When i run the code, i stops at this function – mathias täck Jun 21 '19 at 11:27
  • Please have a look into what @JvdV mentioned. That should help you. Also when you trying to copy something using VBA, try not to separate the `Copy/Paste` command in 2 separate lines. Using `Copy/Paste` in 2 different lines means that you are loading all your data into memory before pasting it. Whereas, `Copy/Paste` in same line avoids this scenario. If you are working with large set of data, this could throw memory errors – Zac Jun 21 '19 at 11:53
  • Welcome to SO. *When i run the code, i stops at this function* is unclear. Does it arises any error number? what error? We need more info – Foxfire And Burns And Burns Jun 21 '19 at 11:57
  • Run-time error '1004': PasteSpecial method of Range class failed – mathias täck Jun 21 '19 at 12:13
  • Have you copied anything before trying to paste it? – Darren Bartrup-Cook Jun 21 '19 at 13:39

0 Answers0