0

When I paste data from a filtered range the data in the rows continuously repeat in the columns to the right until the last Excel column (XFD). I am unable to determine the cause of my pasting issue. I am reusing code from a different project where code works as expected pasting only 1 instance of data. The copy/paste also works as expected when I manually paste the data, regardless of if the copying is done manually or by code. It's just the pasting that is acting differently.

In the current project, I have Filtered data in columns A to P and when I copy and paste then to another sheet all the data is continuously repeated to the right as presented in the generic example -

Copied Data:

Header A Header B
a1 b1
a6 b6

Pasted Data:

Header A Header B Header C Header D Header E Header F
a1 b1 a1 b1 a1 b1
a6 b6 a6 b6 a6 b6

Copy Code:

Set rngFilter = Range("A1:P3472")
rngFilter.Parent.Select
rngFilter.AutoFilter Field:13, Criteria1:="=*criteria*"
rngFilter.Parent.AutoFilter.Range.Copy

Paste Code:

Worksheets(2).Rows("16:16").Select
Selection.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False
PJorya
  • 61
  • 2
  • 2
    You are pasting it to the entire row `Worksheets(2).Rows("16:16").Select` Change that to just the range you want. `Worksheets(2).Rows("A16").Select` – Scott Craner Dec 08 '21 at 19:27
  • 1
    Also. Using `.Select` is slow and should be avoided. See: https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba – Scott Craner Dec 08 '21 at 19:29

0 Answers0