xcaliber13 Posted July 20, 2016 Posted July 20, 2016 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
iamtheky Posted July 20, 2016 Posted July 20, 2016 (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 July 20, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
xcaliber13 Posted July 20, 2016 Author Posted July 20, 2016 OK! That worked perfectly. So read to a variable and use stringleft. Very nice iamtheky Thank you
iamtheky Posted July 20, 2016 Posted July 20, 2016 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. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now