xcaliber13

Excel Help

4 posts in this topic

Does anyone know what I would do for this:

I have an excel spreadsheet that I want to delete the entire row if text = "xyz" in column  D

For $i = 1 To $cLastRow
 $sCell = _Excel_RangeRead($oWorkBook, Default, "D" & $i)
 If $sCell = "xyz" Then _Excel_RangeDelete($oWorkBook.Activesheet, "D" & $i, $xlShiftToLeft, Default)
Next

  I am not having an issue with this function, works great

But that only works if that is the only text in the cell.   How would I do this if the cell contains:    some text  xyz  some more text    ??     So the cell contains other text other than just xyz.    Any help pointing me in the correct direction would be great.  Thank you

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use

If $sCell = "xyz" Then _Excel_RangeDelete($oWorkBook.Activesheet, $oWorkBook.Activesheet.Range("D" & $i).EntireRow, $xlShiftToLeft, Default)

as described here: https://www.autoitscript.com/wiki/Excel_Range#Entire_Row_.2F_Entire_Column

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water,

           Sorry I did not explain correctly.    What I want to do is delete the cell that contains  text  xyz plus other text  and then shift to the left.  The above code works to do that if the cell only contains "xyz" .   How to get this to work if the cell contains more text than just "xyz"?   So the code I posted works if the cell only contains the text "xyz".    What I can't figure out is how to get this to work if the cell contains more text than just "xyz"

Thank you

Share this post


Link to post
Share on other sites

Ah, I see. In this case use _Excel_RangeFind to get an array of cells in the range which contain "xyz".
Then process the array from the last to the first row so you do not delete the wrong rows in Excel.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

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