Copying large amount of cells is making code loop

JOCoyle

New Member
Joined
Sep 30, 2016
Messages
11
Hi,

I have some code which opens another workbook, copies two columns and pastes it into the current workbook. Now the code works perfectly, except that it seems to be repeating itself 4 or 5 times before it is done and subsequently the code following it is also repeating.

Wasn't sure if this was intentional or a strange error but please see the code below as is:

Code:
Sub PullTelStats()
    LoadStatus = "Data from Telephony report selected..."
    LoadText (LoadStatus)
    Dim sht As Worksheet
    Set sht = Worksheets("AAData")
    Dim wbPath As String
    Dim wbName As String
    Dim thisWB As String
    Const wsName As String = "AgentActivity"
    Dim i As Integer
    Dim x As Integer
    wbPath = StripFilename(FilePath)
    wbName = GetFilenameFromPath(FilePath)
    thisWB = ThisWorkbook.Name
    'Method1:
    'Application.ScreenUpdating = False
    'Application.Calculation = xlCalculationManual
    'With sht
    '    For x = 1 To 1017
    '        .Cells(x, 2).Formula = "='" & wbPath & "[" & wbName & "]" & wsName & "'!$G$" & x
    '        .Cells(x, 3).Formula = "='" & wbPath & "[" & wbName & "]" & wsName & "'!$AO$" & x
    '    Next x
    '    Application.Calculation = xlCalculationAutomatic
    '        .Columns(2).NumberFormat = "General"
    '        .Columns(3).NumberFormat = "General"
    'End With
    'Application.ScreenUpdating = True
    'Method2:
    Workbooks.Open (FilePath)
    Application.ScreenUpdating = False
    Workbooks(wbName).Worksheets(wsName).Range("AO:AO").Copy
    Workbooks(thisWB).Worksheets("AAData").Range("C:C").PasteSpecial Paste:=xlPasteValues
    Workbooks(wbName).Worksheets(wsName).Range("G:G").Copy
    Workbooks(thisWB).Worksheets("AAData").Range("B:B").PasteSpecial Paste:=xlPasteValues
    Application.ScreenUpdating = True
    Workbooks(thisWB).Activate
    Worksheets("Loading").Activate
    LoadStatus = "Finished Data Import, Data Clean..."
    LoadText (LoadStatus)
    LoadAmount = LoadAmount + 10
    AddLB Worksheets("Loading"), Worksheets("Loading").Shapes("LoadBar")
    DataClean
End Sub

As you can see the code I tried previously is to go to the sheet, grab each cell and bring it to the current sheet, however this makes my client lock up for a good 30 seconds before being complete, whereas the copy and paste method is so much quicker.

Thanks,
JC.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
add this after every pastespecial line then try...

application.CutCopyMode = false
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,104
Messages
6,170,125
Members
452,303
Latest member
c4cstore

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