I have a program that needs to copy select columns within the same workbook and worksheet. The current code results in Excel crashing, so I'm not sure if it is working or not.
Is there a better way to copy the columns within the same worksheets with the same workbook?
Code:
Sub Macro1()
Dim wb1 As Workbook
'Set it to be the file location, name, and file extension of the Working File
Set wb1 = Workbooks.Open("Z:\XXX\Working File.xlsx")
MsgBox "Copying Fields within Working File"
wb1.Worksheets(1).Columns("G").Copy wb1.Worksheets(1).Columns("H").Value
wb1.Worksheets(1).Columns("J").Copy wb1.Worksheets(1).Columns("O").Value
wb1.Worksheets(1).Columns("K").Copy wb1.Worksheets(1).Columns("N").Value
wb1.Worksheets(1).Columns("M").Copy wb1.Worksheets(1).Columns("P").Value
wb1.Close SaveChanges:=True
End Sub
.Value
at the end. You just want to copy to a range, not Value. But, if you just need values and not formatting/etc, you can just doRange([Destination Range]).Value = Range([copy range]).Value
, i.e.wb1.Worksheets(1).Columns("H").Value = wb1.Worksheets(1).Columns("G").Value
. Also, do you need to use the whole column? – BruceWaynelastRow
for each column. But for now, if it works, it works! – BruceWayne