Delete Excel row with string that contains letter L

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
vmax
Newbie
Posts: 1
Joined: Fri Sep 28, 2012 9:34 pm

Delete Excel row with string that contains letter L

Post by vmax » Fri Sep 28, 2012 9:42 pm

Hello,
I'm trying to set up a script that deletes a row in excel if it finds an L in a string of column 8. What i got is the following:

while>curRow%SCRIPT_DIR%\removeL,Sheet1,curRow,8,LorNotL

Label>same_row_again
if>LorNotL
XLDelRow>>%SCRIPT_DIR%\removeL,Sheet1,curRow
endif
Goto>same_row_again

Let>curRow=curRow+1

endwhile

what's missing is the condition: If the string in cell (curRow,8) contains an L, delete it. The string can look like this for example: "(G-8)(WQL 7)HRS 98)".

I'd be happy if you helped me, thank you.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sat Sep 29, 2012 5:06 am

Try this. Requires Macro Scheduler version 13.

Code: Select all

/// Set these three variables to your specifications ///
Let>file=%desktop_dir%\test1.xls
Let>Sheet=Sheet1
Let>StringToDetect=L
////////////////////////////////////////////////////////

XLOpen>file,0,XLhndl
XLGetSheetDims>XLhndl,Sheet,TotalRows,TotalCols

Let>kk=0
Repeat>kk
  Add>kk,1
  XLGetCell>XLhndl,Sheet,kk,8,cellContents
  Separate>cellContents,StringToDetect,Lres
  WriteLn>%temp_dir%xltest.txt,wres,%cellContents% - %kk%
  If>Lres_count>1
    WriteLn>%temp_dir%xltest.txt,wres,%cellContents% - %Lres_Count%
    XLDelRow>XLhndl,Sheet,kk
    //If you delete a row, be sure to set the row counter down one
    Sub>kk,1
  EndIf
Until>kk=TotalRows

XLSave>XLhndl,file
XLQuit>XLhndl

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts