Avoid Activation

duncan1970

New Member
Joined
Jun 25, 2011
Messages
3
Sub CompareSingle1()
Application.ScreenUpdating = False
Dim csvdir As String
Dim xlsxdir As String
Dim windir As String
ChDir "C:\Users\EricB\Desktop"
Workbooks.Open Filename:="C:\Users\EricB\Desktop\Singlecopy.xlsx"
xlsxdir = "C:\Users\EricB\Desktop\Single2\jun17"
ChDir xlsxdir
For i = 1 To 15000
Workbooks.Open Filename:=xlsxdir & "\jun17_" & i & ".xlsx"
Range("G1").Select
Selection.Copy
Windows("singlecopy").Activate
Range("A1").Select
Cells(Rows.Count, "b").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Workbooks(3).Activate
ActiveWorkbook.Close

Next i
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the board. Can you give a description of what you would like to do. This just looks like it opens a file, copies cell G1 and pastes it in the first blank space in your other workbook 15,000 times. Not sure if you need a workbook to open and close that many times, but we can see what we can come up with.
 
Upvote 0
Try like this

Code:
Sub CompareSingle1()
Application.ScreenUpdating = False
Dim xlsxdir As String
ChDir "C:\Users\EricB\Desktop"
Workbooks.Open Filename:="C:\Users\EricB\Desktop\Singlecopy.xlsx"
xlsxdir = "C:\Users\EricB\Desktop\Single2\jun17"
ChDir xlsxdir
For i = 1 To 15000
    Workbooks.Open Filename:=xlsxdir & "\jun17_" & i & ".xlsx"
    Range("G1").Copy Destination:=Workbooks("singlecopy.xlsx").Sheets(1).Range("B" & Rows.Count).End(xlUp).Offset(1)
    ActiveWorkbook.Close
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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