MrCheese

Big data set excel

3 posts in this topic

#1 ·  Posted (edited)

Hi Guys,

Appreciate the help!

Without getting into details... basically,

So, I have a large data set (about 10k rows, and 10 columns).

I need autoit to select A2, then paste it into an external program.

then, i need it to select B2 and paste it into another field, then C2, into another, D2 into another etc.

Then move onto row 3 and repeat.

Is there an easier way to cycle the row numbers in the loop aside from what I have done before on smaller data sets (ie. <30) where $run is the reference to the addition. Coding up 20k of if $run = blar then blar blar blar seems a little tedious.

I used _Excel_RangeCopyPaste before as shown below.... i am also not sure if some of my code is not necessary. Any help on that would be appreciated also.

 

Thanks for your help!

#include <Excel.au3>
;assist variables etc to specific excel books etc.

Func cellselect()

if $run = 1 then
$data1 = A2
$data2 = B2
$data3 = C2
endif

if $run = 2 then
$data1 = A3
$data2 = B3
$data3 = C3
endif

EndFunc

$run=0
while 1
$run = $run+1
winactivate("spreadsheet title that is open already")
cellselect()
local $oRange = $oWorkbook.ActiveSheet.Range($data1)
_Excel_RangeCopyPaste($oWorkbook.ActiveSheet, $oRange, Default)
Winactivate ("other program")
mouseclick(Left,$pos1x,$pos1y)
send("^v")
sleep(1000)

local $oRange = $oWorkbook.ActiveSheet.Range($data2)
_Excel_RangeCopyPaste($oWorkbook.ActiveSheet, $oRange, Default)
Winactivate ("other program")
mouseclick(Left,$pos2x,$pos2y)
send("^v")
;do stuff here with data ,3,4,5 etc, flicking between excel and program, pasting specific data fields and then exit

WEnd

 

Edited by MrCheese
adding explanation and more code

Share this post


Link to post
Share on other sites



I think I nailed the sequential row loop.

thanks to the UDF example!!

Any ideas about how to do a sequential column grab?

Would you need to manually map A = 1, B = 2 etc?

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

; Create application object and open an example workbook
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open Workbook 1
Local $oWorkbook1 = _Excel_BookOpen($oExcel, @ScriptDir & "/Book1.xlsx", True)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error opening workbook '" & @ScriptDir & "Book1.xlsx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf
$run = 0
$rrdif = 1
$rowpaste = 3
$ttlrun=10

; *****************************************************************************
; Copy a range with 3 rows and 2 columns on the active worksheet.
; Pass the source range as object.
; *****************************************************************************
While $run <$ttlrun
    $run = $run + 1
    $row = $run + $rrdif
    $row2 = $run + $rowpaste
    Local $oRange = $oWorkbook1.ActiveSheet.Range("A" & $row)
    _Excel_RangeCopyPaste($oWorkbook1.ActiveSheet, $oRange, "K" & $row2)

    Local $oRange = $oWorkbook1.ActiveSheet.Range("B" & $row)
    _Excel_RangeCopyPaste($oWorkbook1.ActiveSheet, $oRange, "L" & $row2)

    Local $oRange = $oWorkbook1.ActiveSheet.Range("C" & $row)
    _Excel_RangeCopyPaste($oWorkbook1.ActiveSheet, $oRange, "M" & $row2)
WEnd

 

Share this post


Link to post
Share on other sites

It takes some tim to process 10000 rows the way you do it. Is speed an issue for your script? Means: The faster the better?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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

  • Similar Content

    • LoneWolf_2106
      By LoneWolf_2106
      Hi,
      i have an error:
      ==> The requested action with this object has failed.: $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count $iRowCount = .Range(^ ERROR  
      My code is:
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) Sleep(1000) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count Sleep(1000) _Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet,$aFileList[$i][2] , "AB3:AB"&$iRowCount) I have added some sleep because the application was crashing more often before, so i thought to slow down the code execution.
      But i didn't solve the issue.
      Has anyone an idea of what the problem might be?
      Thanks in advance.
    • water
      By water
      Extensive library to control and manipulate Microsoft Excel charts.
      Written by GreenCan and water.
      Theads: General Help & Support - Example Scripts
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2017-07-21)
      None. The COM error handling related bugs have been fixed.
       
    • LoneWolf_2106
      By LoneWolf_2106
      Hi,
      i have a problem with the deletion of an empty row in Excel.
      My code:
       
      If $vRow_2 = "" Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet,"2", $xlShiftUp,1) EndIf I want to delete the second row. $vRow_2 is an empty cell, "A2".
      After running the code, the second row is not deleted.
      I have tried also:
       
      If $vRow_2 = Null Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet,"2", $xlShiftUp,1) EndIf But it doesn't work.
      Any suggestion?
      Thanks in advance.
    • VeryGut
      By VeryGut
      I'm trying to insert the following formula in cell A2 using my script:
      =if(A1=""; "YES"; "NO")
      To my understanding, the line of code should be similar to this:
      _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2")
      However, it does not work, probably due to the multiple quotation marks that confuse the script :C
      How do I avoid this problem?
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question about Excel, i have to create several charts one below the other dynamically.
      I have thought to use:
       
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count  
      And then to use it in this way:
      $Graph_position = "=Test1!A"&$iRowCount+2&":K"&$iRowCount+24 But it doesn't work with charts.
      Does anyone have a suggestion?