Jump to content
timmyc

Copy/Paste excel cells until cell is blank

Recommended Posts

timmyc

Hey all,

Need a bit of a hand with this one. Essentially i am trying to copy an excel cell, paste it somewhere go back to excel, go down a cell and repeat until the cell is blank. I have a larger chunk of script that i will be using instead of this small task (copy and pasting into notepad) but i just wanted to loop something basic until i can get this working. 

This is my first time playing with AutoIt and excel. I suspect where i am going wrong is that i'm telling it to read a cell range in excel where as i need to tell it to read 1 cell at a time until cell = blank. Should i be adding in some logic where it increases the cell number each loop or should i be building an array from the column then calling back on those values?

 

#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>


;Essentially i am trying to copy an excel cell, paste it somewhere go back to excel, go down a cell and repeat untill the cell is blank

Local $oExcel = _Excel_Open()
Local $sWorkbook = @ScriptDir & "\Book1.xls"
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)

;Unsure if instead of using a cell range i should be getting excel to read one cell, then in the next loop add a 1 to the cell and read again. Eg. Read A1 do function, read A2 do function
Local $aResult = _Excel_RangeRead($oWorkbook,1, "A1:A14")

Do
   WinActivate("Microsoft Excel - Book1.xls")
   Send("{CTRLDOWN}c{CTRLUP}")
   ;Copy cell
   WinActivate("Untitled - Notepad")
   Send("{CTRLDOWN}v{CTRLUP}")
   ;Paste cell
   WinActivate("Microsoft Excel - Book1.xls")
   ;Go down a cell
   Send("{ENTER}{ENTER}")
Until $aResult = ""

Exit

Thanks for your help!

Share this post


Link to post
Share on other sites
water

Use a region as described in the wiki to read all cells until a blank cell is found. Then loop through the resulting array and send the cells to your application.

$oRange = $oWorkBook.Activesheet.Range("A1").CurrentRegion

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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

×