Jump to content
Sign in to follow this  
CE101

Excel: Copying data from one cell to a range of other cells

Recommended Posts

CE101

I can't figure out how to Copy data from one cell to a range of other cells.

For example, there's a formula in cell G2 and I want to copy it cells G3:G7.

Not knowing how this is done I turned on the macro recorder to see what's happening behind the scenes when you do this manually. Here's the VBA code that gets generated....

Example 1

Range("G3").Select
    Selection.Copy
    Range("G4").Select
    ActiveSheet.Paste

Now the question - how is this done in AutoIT.

I checked the AutoIT forum, but didn’t find anything directly relating to this.

I checked MSDN and found the following VBA code...

Example 2

Worksheets("Sheet1").Range("A1:D4").Copy _
        destination:=Worksheets("Sheet2").Range("E5")

So with above VBA examples in mind, I tried the following for AutoIT....

Method #1, based on Example1 above

Error: "The requested action with this object has failed". Arrow pointing to Copy

$oExcel.ActiveSheet.Range("G2").Select
    $oExcel.ActiveSheet.Selection.Copy
    $oExcel.ActiveSheet.Range("G3:G7").Select
    $oExcel.ActiveSheet.Paste

Method #2, based on Example1 above

Error: "The requested action with this object has failed". Arrow pointing to Paste

$oExcel.ActiveSheet.Range("G2").Copy 
    $oExcel.ActiveSheet.Range("G3:G7").paste

Method #3, based on Example1 above

Error: "The requested action with this object has failed". Arrow pointing to Paste

With $oExcel.ActiveSheet.range("G2" )
        .Select
        .Copy
        .Range("G3:G7")
        .Select
        .Paste
    EndWith

Method #4, based on Example2 above

Error: "The requested action with this object has failed". Arrow pointing to Copy

$oExcel.ActiveSheet.Range("G2").Copy($oExcel.ActiveSheet.Range("G3:G7").paste)

Any suggestions would be greatly appreciated. Sample code would be even better.

Share this post


Link to post
Share on other sites
Juvigy

$oExcel = ObjCreate("Excel.Application")

$oExcel.Visible = 1

$oExcel.WorkBooks.Open ("C:\123.xls")

$oExcel.Application.ActiveSheet.Range("B1").Select

$oExcel.Application.Selection.Copy

$oExcel.Application.ActiveSheet.Range("A1").Select

$oExcel.Application.ActiveSheet.Paste

Share this post


Link to post
Share on other sites
CE101

Thank you for your quick & helpful responses.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.