Skip to main content
deleted 101 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

This code do:

  1. CopyCopies a value from "Sheet1"
  2. PastePastes special (as a number) in another sheet "Sheet2"
  3. JumpJumps to the next line

I already did:

  1. Disabled screen refresh

  2. Wrapped the code with Application.EnableEvents = False and Application.Calculation = xlCalculationManual

    1 made the calculation a little faster, but 2 didn't seem to make any effect.


  
    Dim iterations, counter As Integer
    iterations= 10000
    counter = 1

    Do While counter <= iterations
    
    ' copy value from Sheet1
    Sheets("Sheet1").Range("B4").Copy
    
    ' paste value in sheet2
    Sheets("Sheet2").Select
    
    Selection.PasteSpecial Paste:=xlPasteValues
    ActiveCell.Offset(1, 0).Range("A1").Select
    
    counter = counter + 1
        
    Loop

PS1: I usually run 50,000+ iterations (counter = 50000).

My question is: howHow can I improve this code speed?

This code do:

  1. Copy a value from "Sheet1"
  2. Paste special (as a number) in another sheet "Sheet2"
  3. Jump to the next line

I already did:

  1. Disabled screen refresh

  2. Wrapped the code with Application.EnableEvents = False and Application.Calculation = xlCalculationManual

    1 made the calculation a little faster, but 2 didn't seem to make any effect.


 
    Dim iterations, counter As Integer
    iterations= 10000
    counter = 1

    Do While counter <= iterations
    
    ' copy value from Sheet1
    Sheets("Sheet1").Range("B4").Copy
    
    ' paste value in sheet2
    Sheets("Sheet2").Select
    
    Selection.PasteSpecial Paste:=xlPasteValues
    ActiveCell.Offset(1, 0).Range("A1").Select
    
    counter = counter + 1
        
    Loop

PS1: I usually run 50,000+ iterations (counter = 50000).

My question is: how can I improve this code speed?

This code:

  1. Copies a value from "Sheet1"
  2. Pastes special (as a number) in another sheet "Sheet2"
  3. Jumps to the next line

I already:

  1. Disabled screen refresh

  2. Wrapped the code with Application.EnableEvents = False and Application.Calculation = xlCalculationManual

    1 made the calculation a little faster, but 2 didn't seem to make any effect.

 
Dim iterations, counter As Integer
iterations= 10000
counter = 1

Do While counter <= iterations

' copy value from Sheet1
Sheets("Sheet1").Range("B4").Copy

' paste value in sheet2
Sheets("Sheet2").Select

Selection.PasteSpecial Paste:=xlPasteValues
ActiveCell.Offset(1, 0).Range("A1").Select

counter = counter + 1
    
Loop

I usually run 50,000+ iterations (counter = 50000).

How can I improve this code speed?

Source Link
user15468
user15468

Copy and paste to different worksheets

This code do:

  1. Copy a value from "Sheet1"
  2. Paste special (as a number) in another sheet "Sheet2"
  3. Jump to the next line

I already did:

  1. Disabled screen refresh

  2. Wrapped the code with Application.EnableEvents = False and Application.Calculation = xlCalculationManual

    1 made the calculation a little faster, but 2 didn't seem to make any effect.


    Dim iterations, counter As Integer
    iterations= 10000
    counter = 1

    Do While counter <= iterations
    
    ' copy value from Sheet1
    Sheets("Sheet1").Range("B4").Copy
    
    ' paste value in sheet2
    Sheets("Sheet2").Select
    
    Selection.PasteSpecial Paste:=xlPasteValues
    ActiveCell.Offset(1, 0).Range("A1").Select
    
    counter = counter + 1
        
    Loop

PS1: I usually run 50,000+ iterations (counter = 50000).

My question is: how can I improve this code speed?