Sign in to follow this  
Followers 0
xcaliber13

StringRegExp or something else?

4 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

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

Share this post


Link to post
Share on other sites

OK! That worked perfectly.  So read to a variable and use stringleft.  Very nice iamtheky   Thank  you

Share this post


Link to post
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.


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

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
Sign in to follow this  
Followers 0