How can I loop this

  • Thread starter Thread starter Steve B
  • Start date Start date
S

Steve B

I am trying to copy paste this range. Is there a way to loop this if
I want to change the variable "X" to 1 to 100?


Dim Wb1 As Workbook
Dim Wb2 As Workbook
Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
Set Wb2 = Workbooks.Open("C:\portfolio\Example X.xls")
Wb2.Sheets("Cashflow1").Range("L23:U47").Copy _
Wb1.Sheets("output").Range("c4")

Wb2.Close False
Application.ScreenUpdating = True

Thanks in advance
 
dim x as integer

for x=1 to 100
.....
Set Wb2 = Workbooks.Open("C:\portfolio\Example " & x & ".xls")
.....
next x
 
SteveB try somthing like this

Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim FileN As String
Dim i As Integer


Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
For i = 1 To 100
FileN = "C:\portfolio\Example" & i & ".xls"

Set Wb2 = Workbooks.Open(FileN)
Wb2.Sheets("Cashflow1").Range("L23:U47").Copy _
Wb1.Sheets("output").Range("c4")

Wb2.Close False
Next i

Application.ScreenUpdating = True
 
Back
Top