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:
add/amend the red:
Code:
[COLOR=Red]If Left(MyFileName, 2) = "10" Then myRngStr = "E14:E29" Else myRngStr = "G14:G29"[/COLOR]
    Sheets("Fin Review Team").Range([COLOR=Red]myRngStr[/COLOR]).Copy
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,224,616
Messages
6,179,910
Members
452,949
Latest member
beartooth91

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