VBA Code to loop thru filtered data and copy/paste pdfs

TexasChaz

New Member
Joined
Apr 5, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I am trying to copy designated pdf files from multiple folders into one designated folder (DestFolder) based upon file names and folder locations filtered on a spreadsheet (sheet 1).

The columns of data on “Sheet 1” span from column B to AY. I have code that has already successfully filtered this data based on criteria. The filters and headers are in row 2. Folder Paths exist in column “Q” and file names are in column “O”. I need to increment through the filter list and copy a pdf file with the name designated in column “O” which is located in folder designated by the path in column “Q” of the same row. I then need to paste that pdf file in a folder called “DestFolder”. I then need to loop to the next row to do the same thing until I reach the end of the filtered list. I have tried to use a mix match of code I have found. No errors but it is stopping at the first filtered line in column “O”.

Sheets("sheet 1").Activate
ActiveSheet.Unprotect Password:=""

Dim FolderName As Variant
Dim FileName As Variant
Range("Q2").Select
ActiveCell.Offset(1, 0).Activate
Do Until Selection.EntireRow.Hidden = False
If Selection.EntireRow.Hidden = True Then
ActiveCell.Offset(1, 0).Activate
End If
FolderName = ActiveCell.Value
ActiveCell.Offset(0, -2).Select
FileName = ActiveCell.Select

FileCopy "FolderName" & FileName.Value, "DestFolder" & FileName.Value

Loop
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,213,494
Messages
6,113,974
Members
448,537
Latest member
Et_Cetera

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