Moving Columns of Data in VBA Code Causes Entire Macro to Crash.
I'm working on a macro to manipulate a large data file. This macro successfully applies filters, creates tables, creates new tabs, adds cell borders, renames columns, etc. Everything works as intended and the whole thing runs in maybe 3-4 seconds.
When I add the below code to simply move some of the columns around at the beginning of the macro, the whole thing freaks out and I can't figure out why. The macro starts to run VERY slowly, data doesn't get copied/pasted correctly, borders are applied incorrectly, filters are left on....it doesn't make any sense to me.
Columns("D:D").Select
' Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
' Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
' Columns("Q:R").Select
' Selection.Cut
' Range("D1").Select
' ActiveSheet.Paste
' Columns("Q:R").Select
' Selection.Delete Shift:=xlToLeft
' Columns("Y:Y").Select
' Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
' Columns("AG:AG").Select
' Selection.Cut
' Range("Y1").Select
' ActiveSheet.Paste
' Columns("X:X").Select
' Selection.Cut
' Range("AG1").Select
' ActiveSheet.Paste
' Columns("X:X").Select
' Selection.Delete Shift:=xlToLeft
' Range("AH1").Select
' ActiveCell.FormulaR1C1 = "CUC ECD"
' Application.CutCopyMode = False
Without this code, everything is perfect. With this code, the whole thing freaks out. Please help me.
[link] [comments]
Want to read more?
Check out the full article on the original site