Jump to content

Recommended Posts

Posted

How to Copy All Data from column A (Excel2) to column C (Excel1) 

 

Global $oExcel = _Excel_Open(True)
      Global $oWorkbook1 = _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel1.xls")

      Global $oExcel2 = _Excel_Open(True)
      Global $oWorkbook2 = _Excel_BookOpen($oExcel2, @ScriptDir & "\Extras\_Excel2.xls")

Local $oRange = $oWorkbook2.Worksheets(1).Range("A")
_Excel_RangeCopyPaste($oWorkbook1.Worksheets(1), $oRange, "C")

 

Posted (edited)

A few different ways:

#include <Excel.au3>
Global $oExcel = _Excel_Open()
Global $oWorkbook1 = _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel1.xls")
Global $oWorkbook2 = _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel2.xls")

;~ Option 1 - Using ActiveSheet
Local $oRange1 = $oWorkbook1.ActiveSheet.Columns("A")
Local $oRange2 = $oWorkbook2.ActiveSheet.Columns("C")
_Excel_RangeCopyPaste($oWorkbook1.ActiveSheet, $oRange1, $oRange2)

;~ Option 2 - Using Worksheet index
Local $oRange1 = $oWorkbook1.Worksheets(1).Columns("A")
Local $oRange2 = $oWorkbook2.Worksheets(1).Columns("C")
_Excel_RangeCopyPaste($oWorkbook1.Worksheets(1), $oRange1, $oRange2)

;~ Option 3 - Using Worksheet name
Local $oRange1 = $oWorkbook1.Worksheets("Sheet1").Columns("A")
Local $oRange2 = $oWorkbook2.Worksheets("Sheet1").Columns("C")
_Excel_RangeCopyPaste($oWorkbook1.Worksheets(1), $oRange1, $oRange2)

 

Edited by Subz
Posted
3 hours ago, Subz said:

A few different ways:

#include <Excel.au3>
Global $oExcel = _Excel_Open()
Global $oWorkbook1 = _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel1.xls")
Global $oWorkbook2 = _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel2.xls")

;~ Option 1 - Using ActiveSheet
Local $oRange1 = $oWorkbook1.ActiveSheet.Columns("A")
Local $oRange2 = $oWorkbook2.ActiveSheet.Columns("C")
_Excel_RangeCopyPaste($oWorkbook1.ActiveSheet, $oRange1, $oRange2)

;~ Option 2 - Using Worksheet index
Local $oRange1 = $oWorkbook1.Worksheets(1).Columns("A")
Local $oRange2 = $oWorkbook2.Worksheets(1).Columns("C")
_Excel_RangeCopyPaste($oWorkbook1.Worksheets(1), $oRange1, $oRange2)

;~ Option 3 - Using Worksheet name
Local $oRange1 = $oWorkbook1.Worksheets("Sheet1").Columns("A")
Local $oRange2 = $oWorkbook2.Worksheets("Sheet1").Columns("C")
_Excel_RangeCopyPaste($oWorkbook1.Worksheets(1), $oRange1, $oRange2)

 

Thank you Subz, I try 

Local $oRange1 = $oWorkbook1.ActiveSheet.Columns("A:Z")
Local $oRange2 = $oWorkbook2.ActiveSheet.Columns("A:Z")
_Excel_RangeCopyPaste($oWorkbook1.ActiveSheet, $oRange1, $oRange2)

I worked :) 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...