locked
Find method in excel using powershell RRS feed

  • Question

  • I am trying to find values in a column in one excel sheet in a column in another sheet, however for example I have the word samsung which I am searching for.. however the other column has the value samsung5000 in it. Since the entire cells contents are not matching, I want the find operation to return false. Only if the entire cells contents match it should return true. How can I achieve this in powershell. I have the below code:
    for($r=1;$r -le $max;$r++)
         {
              if($sheet1.UsedRange.Find($searchstring))
                   {
                        #Do Something
                   }
         }


    • Edited by Admin66 Thursday, October 10, 2019 11:30 PM
    Thursday, October 10, 2019 11:29 PM

All replies

  • You have to add the corr3ect search restrictions to the "Find" method.  You also need to restrict the range to the target column.

    Look at the docs for "Find"


    \_(ツ)_/

    Friday, October 11, 2019 12:53 AM
  • You might take a look at the module ImportExcel - that could make your life a little easier I think.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, October 11, 2019 12:53 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, November 8, 2019 2:03 PM