Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make a for loop faster in vba when copying pasting columns

I have a vba script that uses a for loop to copy rows to columns, but this method is very slow when running. Is there a faster way of accomplishing this.

enter image description here

As you can see below, I have data in the ‘my data’ row and I need each of the rows copied and pasted to the next column to the right. For example, the 1 needs to be copied and pasted all the way to the columns to the right from range(X44:AY44) and so on.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Below is the script that works, but it is too slow for processing.

Sub CopyPasteSV4_SV30()

    Dim r As Range, cell As Range
    Dim i As Integer
    i = 44
    
    For Each cell In Range("X44:X63")
        Range("X" & i).Select
        Selection.Copy
        Range("Y" & i, Range("AY" & i)).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        i = i + 1
    Next cell
End Sub

>Solution :

There is no need to loop, use Select, or use .Copy/.PasteSpecial. Use value transfer.

Range("Y44:AY63").Value = Range("X44:X63").Value
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading