What am I doing wrong in this copy, paste macro?

copleyr

Active Member
Joined
Aug 24, 2009
Messages
381
The following macro will go into the "Fin Review Team" tab of each of these files and copy G14:G29 and paste it into a blank sheet.

Well, it is supposed to paste it into a blank sheet. The problem is, when it pastes, nothing gets pasted, it is just blank.

What am I doing wrong here?

Thank you in advance!



Code:
Sub Copy_files() 
Dim MyPathName As String
Dim MyFileName As String
Dim NumChars As Long
Dim X As Long
Dim SummarySheet As String
Workbooks.Add
SummarySheet = ActiveWorkbook.Name
MyPathName = "C:\Users\Desktop\All/" 'Change this to the folder and filetypes you want to return
MyFileName = Dir(MyPathName)
X = 0
Do While MyFileName <> ""
    X = X + 16
    Workbooks.Open MyPathName & MyFileName, False
    Application.DisplayAlerts = False
    Sheets("Fin Review Team").Range("G14:G29").Copy
    Workbooks(SummarySheet).Activate
    Range("B" & X & ":B" & X).PasteSpecial xlPasteValuesAndNumberFormats
    Range("B" & X & ":B" & X).PasteSpecial xlPasteFormats
    Workbooks(MyFileName).Close False
    MyFileName = Dir
Application.DisplayAlerts = True
Loop
End Sub
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I think the final character of your path name should be "\", not "/".

Try stepping through the code using F8 to see if the code is working as expected.
 
Upvote 0
Hey I just checked. That's not the issue as it still looks into the correct path. Thanks for responding :)
 
Last edited:
Upvote 0
It's official. I'm baffled. Cannot figure out why it is not pasting information!. It is highlighting all of the correct areas for pasting, but nothing is getting pasted....
 
Upvote 0
It works here!
The only thing that I can think of is if
Sheets("Fin Review Team").Range("G14:G29")
is blank in most/all of the workbooks you're opening.
 
Upvote 0
Actually p45Cal, I figured it out, for the files in the directory that start with "10", the information is in the column "E" range. Thanks for the help!

Would anybody be able to help with with an If-then statement in this macro, for files that begin with "10", to copy the "E" range, rather than "G"?
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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