Copy Paste Values Only( XlPasteValues )


Answer :

If you are wanting to just copy the whole column, you can simplify the code a lot by doing something like this:



Sub CopyCol()

Sheets("Sheet1").Columns(1).Copy

Sheets("Sheet2").Columns(2).PasteSpecial xlPasteValues

End Sub


Or



Sub CopyCol()

Sheets("Sheet1").Columns("A").Copy

Sheets("Sheet2").Columns("B").PasteSpecial xlPasteValues

End Sub


Or if you want to keep the loop



Public Sub CopyrangeA()

Dim firstrowDB As Long, lastrow As Long
Dim arr1, arr2, i As Integer

firstrowDB = 1
arr1 = Array("BJ", "BK")
arr2 = Array("A", "B")

For i = LBound(arr1) To UBound(arr1)

Sheets("Sheet1").Columns(arr1(i)).Copy

Sheets("Sheet2").Columns(arr2(i)).PasteSpecial xlPasteValues

Next
Application.CutCopyMode = False

End Sub


since you only want values copied, you can pass the values of arr1 directly to arr2 and avoid copy/paste. code inside the loop:



      Sheets("SheetB").Range(arr2(i) & firstrowDB).Resize(lastrow, 1).Value = .Range(.Cells(1, arr1(i)), .Cells(lastrow, arr1(i))).Value


Personally, I would shorten it a touch too if all you need is the columns:



For i = LBound(arr1) To UBound(arr1)
Sheets("SheetA").Columns(arr1(i)).Copy
Sheets("SheetB").Columns(arr2(i)).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Next


as from this code snippet, there isnt much point in lastrow or firstrowDB



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable