CE101 Posted July 22, 2010 Share Posted July 22, 2010 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. Link to comment Share on other sites More sharing options...
Juvigy Posted July 22, 2010 Share Posted July 22, 2010 $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 Link to comment Share on other sites More sharing options...
ionut Posted July 22, 2010 Share Posted July 22, 2010 Hi, You can check this post, example #2.Ionut Link to comment Share on other sites More sharing options...
CE101 Posted July 22, 2010 Author Share Posted July 22, 2010 Thank you for your quick & helpful responses. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now