Jump to content

Excel Loop/If help.


Go to solution Solved by 13lack13lade,

Recommended Posts

Hi Guys!
 
I am using autoit with excel and want to skip blank rows in my excel read cell otherwise run the loop, i also want to run the loop upto a max 10000 lines.
 
The way i am thinking of doing it is:
 
If $TypCellValue = " " THEN skip row ELSE do my send commands.
 
but how do i tell autoit to skip or move to next row in excel?
 
Would it be something like this?
 
If $TypCellValue = "" then $i = 1 (+1) to 10000 ? or something like that
 
 
 
For $i = 1 To 10000 ;Loop
$TypCellValue = _ExcelReadCell($oExcel, $i, 1)
$CityCellValue = _ExcelReadCell($oExcel, $i, 2)
    $PrdCellValue = _ExcelReadCell($oExcel, $i, 3)
   Sleep(1000)
   WinActivate("program")


   Send("C") 
   Sleep(500)
   Send("{TAB}")
   Sleep(500)
   Send($TypCellValue) 
   Sleep(700)
   Send($CityCellValue)
   Sleep(700)
   Send($PrdCellValue)
   Sleep(1000)
   Send("{ENTER}")
   Sleep(700)
Edited by 13lack13lade
Link to comment
Share on other sites

I would think it would be easier to just run your loop and only perform actions if the cell is not blank.

For $i = 1 To 10000 ;Loop
    $TypCellValue = _ExcelReadCell($oExcel, $i, 1)
    $CityCellValue = _ExcelReadCell($oExcel, $i, 2)
    $PrdCellValue = _ExcelReadCell($oExcel, $i, 3)
    If $TypCellValue <> "" Then
        Sleep(1000)
        WinActivate("program")
        Send("C")
        Sleep(500)
        Send("{TAB}")
        Sleep(500)
        Send($TypCellValue)
        Sleep(700)
        Send($CityCellValue)
        Sleep(700)
        Send($PrdCellValue)
        Sleep(1000)
        Send("{ENTER}")
        Sleep(700)
    EndIf
Next
Edited by GMK
Link to comment
Share on other sites

Thanks for your reply GMK however doesnt appear to like that at all, im not sure if its because of the other loop i have after it but it still does the same thing

 

seems like its missing the loop completely because some of the rows contain data and therefore skips straight to the second loop sending DN...

i just need it to skip down 1 row untill $typecellvalue contains anything.

  
For $i = 1 To 10000 ;Loop
    $TypCellValue = _ExcelReadCell($oExcel, $i, 1)
    $CityCellValue = _ExcelReadCell($oExcel, $i, 2)
    $PrdCellValue = _ExcelReadCell($oExcel, $i, 3)
sleep (2000)
winactivate("Calypso Host - Test1")
  sleep (700)
    If $TypCellValue <> "" Then
        Send("C")
        Sleep(500)
        Send("{TAB}")
        Sleep(500)
        Send($TypCellValue)
        Sleep(700)
        Send($CityCellValue)
        Sleep(700)
        Send($PrdCellValue)
        Sleep(1000)
        Send("{ENTER}")
        Sleep(700)
EndIf


   
  If $TypCellValue = "H" Then
 Send("{TAB 4}")
  Else
 Send("{TAB 6}")
  EndIf
   
   Sleep(700)
   send("DN")
   Sleep(700)
   send("{ENTER}")
   Sleep(700)
   send("{LSHIFT}+{DEL}")
   Sleep(700)
   send("{ENTER}")
   sleep(700)
   send("{LSHIFT}+{DEL}")
   Sleep(700)
   send("{ENTER}")
   Sleep(700)
   send("{LSHIFT}+{DEL}")
   Sleep(700)
   send("{ENTER}")
   sleep(700)
Edited by 13lack13lade
Link to comment
Share on other sites

It is a good idea to NOT mix access to Excel (Word, Outlook etc.) via COM and the GUI. That's a nightmare to debug.

Everything (most) you can do via the GUI can be done using COM.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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