'Copy Multiple Table Columns and Paste Values to New Columns
I have a table where I need to copy/paste_values for two columns into two existing columns, so the formulas running in another column will have the correct returns. I have the below code that I found online that allows me to copy and paste a single column, but I need to do multiple columns (they are adjacent). So what I want to do is copy Columns H and I and pastes the vaules into J and K. I am a novice, so this is a struggle for me. Any help would be appreciated.
Sub PasteValues()
Dim H As String
Dim I As String
Dim J As String
Dim K As String
H = "Formula Start"
I = "Formula Stop"
J = "Shift Start"
K = "Shift Stop"
Set tbl = ActiveSheet.ListObjects("Activity_Report")
Range("Activity_Report[" & H & "]").Copy
Range("Activity_Report[" & J & "]").PasteSpecial xlPasteValues
Range("Activity_Report[" & I & "]").Copy
Range("Activity_Report[" & K & "]").PasteSpecial xlPasteValues
Application.cutCoptyMode = False
End
Solution 1:[1]
This worked for me using the tbl object directly and avoiding the copy/paste:
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("Table1")
tbl.ListColumns("Col3").DataBodyRange.Value = tbl.ListColumns("Col1").DataBodyRange.Value
tbl.ListColumns("Col4").DataBodyRange.Value = tbl.ListColumns("Col2").DataBodyRange.Value
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tim Williams |
