Jump to content

Excel Help


xcaliber13
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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