Jump to content

StringRegExp or something else?


Recommended Posts

I have this to delete a row in excel

For $i = $iLastRow To 1 Step -1
      If _Excel_RangeRead($oWorkbook, Default, "C" & $i) = "Q9967" Then
           $oExcel.Rows($i).Delete
       EndIf
Next

Works great but how do I delete a row  in c column if  the data in the cells starts with Q99.    So not only will it delete Q9967, but also Q9968, Q9969, etc.  I started to write For/Next loops for each different data set but there must be a better way.  I was thinking StringRegExp but really not sure how to get that to work or even if that is the way to get there.   Thank you

Link to comment
Share on other sites

maybe something similar to:

For $i = $iLastRow To 1 Step -1
        $sXLread = _Excel_RangeRead($oWorkbook, Default, "C" & $i)
        If stringleft($sXLread , 3) = "Q99" Then
           $oExcel.Rows($i).Delete
       EndIf
Next

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

reading to the variable probably isnt necessary, just better for debugging

If stringleft(_Excel_RangeRead($oWorkbook, Default, "C" & $i) , 3) = "Q99" Then

should work fine, but combining a bunch of functions together isnt recommended lest the return is reliable.  If later you want to add an if error check on the rangeread, or make sure that string isnt blank, or reuse that string to save you a costly second read; you need it separately.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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...