I've been using the following code for a few years to flip spreadsheet data around without issue. Recently however I received a large data set (about 5X larger than those I typically work with and the macro eventually runs out of resources and stops. Typically this runs instantly. I've tried it with screenupdating off and on and it has the same result along with various methods to clear the clipboard after the copy past sequences, they all have the same result. Obviously I have something wrong with my code. I can cut the data set in half and run it twice and it will work but I would prefer to know what is causing the out of resources crash. After a certain number of loops you can watch it get progressively slower each loop until eventually it crashes. Can someone tell me what I am doing wrong with the code below? Thanks
Code:
Sub flip()
'paste analytes
Do While Range("W2").Value > 0
Dim LR
Range("s21:s73").Select
Selection.Copy
LR = Range("s" & Rows.Count).End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("w21:y73").Select
Selection.Copy
Range("s21").End(xlDown).Offset(-52, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("w2:w19").Select
Selection.Copy
HDrng1 = Range("a21").End(xlDown).Offset(1, 0).Row
HDrng2 = Range("s21").End(xlDown).Offset(0, -1).Row
HDrange = "(a" & HDrng1 & ":" & "r" & HDrng2 & ")"
Range(HDrange).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Columns("w:y").Select
Selection.Delete Shift:=xlToLeft
Range("w2").Select
Loop
End Sub