Skip to content

Instantly share code, notes, and snippets.

@aaira-a
Last active August 29, 2015 14:21
Show Gist options
  • Save aaira-a/4df8a3df9205cceafcb1 to your computer and use it in GitHub Desktop.
Save aaira-a/4df8a3df9205cceafcb1 to your computer and use it in GitHub Desktop.
xls vba script to copy multiple columns to other workbook
Sub CopyColumnsToOtherWorkbook()
Dim srcBook As Workbook
Dim srcSheet As Worksheet
Dim destSheet As Worksheet
Set srcBook = Workbooks.Open("C:\vba\source.xlsm", ReadOnly = True)
Set srcSheet = srcBook.Worksheets("SheetName")
Set destSheet = ThisWorkbook.Worksheets("SheetName")
srcSheet.Range("H2:H4").Copy
destSheet.Range("D3:D5").PasteSpecial (xlPasteValues)
srcSheet.Range("T2:T4").Copy
destSheet.Range("H3:H5").PasteSpecial (xlPasteValues)
srcBook.Close
ThisWorkbook.Save
ThisWorkbook.Close
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment