Copy Paste without changing sheets

ogromano

New Member
Joined
Jun 20, 2013
Messages
2
Hi all... first post here. I tried looking for this in various Copy/Paste threads but couldn't find exactly what I needed...

The following code works fine except for the fact that it takes a long time (2 to 3 secs in 5 lines) for this for loop to run and I'd like it to do the pasting in the background without changing to the destination (for archiving) sheet at all. In reality, the pasting is just for later use, the end user won't use it.


Code:
numlineas = WorksheetFunction.Sum(Range("a17:a36"))
contador = 0
Set rng = Sheets("Alta Pedido").Range("a17:a36")
Set primlinea = Sheets("Alta Pedido").Range("a16:i16") 'header row in table from where to offset

For Each contador In rng    If contador < numlineas Then
        Sheets("Alta Pedido").Range("b7").Copy Worksheets("Datos Cotizaciones").Range("A1").End(xlDown).Offset(1, 0)
        'Selection.Activate
        'MsgBox (contador)
        Sheets("Alta Pedido").Range("B8:B14").Copy
        Worksheets("Datos Cotizaciones").Range("A1").End(xlDown).Offset(0, 2).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
        Sheets("Alta Pedido").Range("e8:e10").Copy
        Worksheets("Datos Cotizaciones").Range("A1").End(xlDown).Offset(0, 9).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
        primlinea.Offset(contador, 0).Copy
        Worksheets("Datos Cotizaciones").Range("A1").End(xlDown).Offset(0, 12).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
     Else
        Worksheets("Alta pedido").Activate
        Application.CutCopyMode = False
        Exit For
        
        
    End If
Next contador

Thanks in advance...

(as a side note: I'm starting to use VB again and I would appreciate any suggestions to simplify the code...)
 
Have you got
Code:
Application.screenupdating=False
AND
Application.screenupdating =True
at the beginning and end of your code ???
 
Upvote 0
Hey, that worked perfectly... thanks a lot. Quick and painless straight to the point solution... just what I needed. :)
 
Upvote 0

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