Copy/Paste Filtered Table x Number of Times

wdp74

New Member
Joined
Jun 24, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I have a table on Sheet2 that is filtered to show certain data. I need to copy all the shown data (rows C:E) to Sheet3 (cell A5) and has to be copied x number of time based on value from Sheet1 (cell B4). For example, if the Sheet1 Cell B4 has "10", the shown filtered data will be copied from Sheet 2 and Pasted sheet 3, 10 times.

Any help will be appreciated!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Apologies, I mean it has to be pasted x number of times....
 
Upvote 0
Does your Table have headers? If yes, do you want the headers included in the pastes or just the filtered data body range?
Do you want any empty rows between pastes if x>1?
 
Upvote 0
This will paste the data body range x times as values with no empty rows between pastes.
VBA Code:
Sub PasteFilteredTable()
Dim LO As ListObject, NumTimes As Long, NxRw As Long, Ctr As Long
Application.ScreenUpdating = False
Set LO = Sheets("Sheet2").ListObjects("Table1")
NumTimes = Sheets("Sheet1").Range("B4").Value
NxRw = 5
If NumTimes > 0 Then
    LO.DataBodyRange.SpecialCells(xlCellTypeVisible).Copy
    Do
    With Sheets("Sheet3")
        .Cells(NxRw, "A").PasteSpecial Paste:=xlValues
        Ctr = Ctr + 1
        NxRw = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
    End With
    Loop While Ctr < NumTimes
End If
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Does your Table have headers? If yes, do you want the headers included in the pastes or just the filtered data body range?
Do you want any empty rows between pastes if x>1?

Hi Joe Moe! The table had headers but I do not want them copied/pasted.

Wow! This works great. Only thing, what if I only needed 3 columns (Headers for columns C,D,E - Low, Mid, High).
 
Upvote 0
Figured it out but couldn't have done it without your help. Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top