baamr Posted February 15, 2023 Posted February 15, 2023 (edited) Hi, Case I need to find excact value of the first cell with D3. In my search it returns the cell($AK$24) including D33 cause this includes D3. How can I go around this so it only puts out the “real”value of the first cell including D3 In this case it should be $AK$25 Edited February 15, 2023 by baamr removed one pic
ioa747 Posted February 15, 2023 Posted February 15, 2023 (edited) then search for 'D3,' since the ', ' is there or put a space after each value D3 , D33 , D22 and then search for 'D3 ' Edited February 15, 2023 by ioa747 I know that I know nothing
water Posted February 15, 2023 Posted February 15, 2023 Or process the array the search for D3 returns, stringsplit the value cell and check the returned array for correct values. Can provide an example if needed. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Moderators Melba23 Posted February 15, 2023 Moderators Posted February 15, 2023 Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Solution mistersquirrle Posted February 16, 2023 Solution Posted February 16, 2023 (edited) I would suggest looking at StringSplit: https://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm Like water said, iterate over the array checking the 'Value' column by using StringSplit (with both space and comma as your delimiters). You can then check each value separately. Something like this: #include <StringConstants.au3> Local Enum $eHeader_Sheet, $eHeader_Name, $eHeader_Cell, $eHeader_Value, $eHeader_Formula, $eHeader_Comment, _ $eHeader_Max Local $aArray[][$eHeader_Max] = [ _ ['Sheet0', '', '$AK$24', 'D1, D2, D33, D36', 'D1, D2, D33, D36', ''], _ ['Sheet0', '', '$AK$25', 'D3, D99', 'D3, D99', ''], _ ['Sheet0', '', '$AZ$25', 'D3, D99', 'D3, D99', ''], _ ['Sheet0', '', '$AK$32', 'D27, D28, D29, D30, D31', 'D27, D28, D29, D30, D31', ''], _ ['Sheet0', '', '$AK$61', 'LED1, LED2, LED3, LED4, LED5', 'LED1, LED2, LED3, LED4, LED5', ''] _ ] Local $aSplit Local $sCellToSearchFor = 'D3' Local $bFound = False For $iRow = 0 To UBound($aArray) - 1 $bFound = False $aSplit = StringSplit($aArray[$iRow][$eHeader_Value], ' ,', $STR_NOCOUNT) For $iValue = 0 To UBound($aSplit) - 1 If StringCompare(StringStripWS($aSplit[$iValue], $STR_STRIPALL), $sCellToSearchFor) = 0 Then ConsoleWrite(@TAB & 'Found ' & $sCellToSearchFor & ' reference in row ' & $iRow & ': ' & $aArray[$iRow][$eHeader_Value] & ', Cell: ' & $aArray[$iRow][$eHeader_Cell] & @CRLF) $bFound = True ExitLoop EndIf Next If Not $bFound Then ConsoleWrite('Not found in row: ' & $iRow & @CRLF) EndIf Next Exit I'm using StringCompare instead of just " = " because it can be a bit safer occasionally when comparing if strings are equal. Also, StringStripWS to remove any whitespace when doing the comparison, just in case there's extra spaces. If you wanted to stop searching after the first match just do ExitLoop 2, and it'll exit both For loops. Edited February 16, 2023 by mistersquirrle Updated code We ought not to misbehave, but we should look as though we could.
baamr Posted February 16, 2023 Author Posted February 16, 2023 15 hours ago, ioa747 said: then search for 'D3,' since the ', ' is there or put a space after each value D3 , D33 , D22 and then search for 'D3 ' It could work but some places in sheet do not have commas, only one value. Commas occurs only when there is more than one value in cell.
baamr Posted February 16, 2023 Author Posted February 16, 2023 3 hours ago, mistersquirrle said: I would suggest looking at StringSplit: https://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm Like water said, iterate over the array checking the 'Value' column by using StringSplit (with both space and comma as your delimiters). You can then check each value separately. Something like this: #include <StringConstants.au3> Local Enum $eHeader_Sheet, $eHeader_Name, $eHeader_Cell, $eHeader_Value, $eHeader_Formula, $eHeader_Comment, _ $eHeader_Max Local $aArray[][$eHeader_Max] = [ _ ['Sheet0', '', '$AK$24', 'D1, D2, D33, D36', 'D1, D2, D33, D36', ''], _ ['Sheet0', '', '$AK$25', 'D3, D99', 'D3, D99', ''], _ ['Sheet0', '', '$AZ$25', 'D3, D99', 'D3, D99', ''] _ ] Local $aSplit Local $sCellToSearchFor = 'D3' For $iRow = 0 To UBound($aArray) - 1 $aSplit = StringSplit($aArray[$iRow][$eHeader_Value], ' ,', $STR_NOCOUNT) For $iValue = 0 To UBound($aSplit) - 1 If StringCompare(StringStripWS($aSplit[$iValue], $STR_STRIPALL), $sCellToSearchFor) = 0 Then ConsoleWrite(@TAB & 'Found ' & $sCellToSearchFor & ' reference in row ' & $iRow & ': ' & $aArray[$iRow][$eHeader_Value] & ', Cell: ' & $aArray[$iRow][$eHeader_Cell] & @CRLF) ExitLoop EndIf Next ConsoleWrite('Not found in row: ' & $iRow & @CRLF) Next Exit I'm using StringCompare instead of just " = " because it can be a bit safer occasionally when comparing if strings are equal. Also, StringStripWS to remove any whitespace when doing the comparison, just in case there's extra spaces. If you wanted to stop searching after the first match just do ExitLoop 2, and it'll exit both For loops. Unfortunately it does not work. This example outputs the same fault as originally. It gives result in every row. My only result should be in row 1 were D3 occurs first.
mistersquirrle Posted February 16, 2023 Posted February 16, 2023 (edited) 8 minutes ago, baamr said: Unfortunately it does not work. This example outputs the same fault as originally. It gives result in every row. My only result should be in row 1 were D3 occurs first. Could you post what the output is? As mentioned in my post, if you want to stop at the first found instance, use ExitLoop 2, or better yet, put my example loops in a function and use Return to return the row or cell that has the first match. Here's what I get for output with my example (updated to include all the rows in your example): Not found in row: 0 Found D3 reference in row 1: D3, D99, Cell: $AK$25 Found D3 reference in row 2: D3, D99, Cell: $AZ$25 Not found in row: 3 Not found in row: 4 If it's not working, then please make an example or post your code so that we can run it and see why it doesn't work. Just saying that it doesn't work without more information isn't helpful for us to give you a solution. Edited February 16, 2023 by mistersquirrle We ought not to misbehave, but we should look as though we could.
baamr Posted February 16, 2023 Author Posted February 16, 2023 29 minutes ago, mistersquirrle said: Could you post what the output is? As mentioned in my post, if you want to stop at the first found instance, use ExitLoop 2, or better yet, put my example loops in a function and use Return to return the row or cell that has the first match. Here's what I get for output with my example (updated to include all the rows in your example): Not found in row: 0 Found D3 reference in row 1: D3, D99, Cell: $AK$25 Found D3 reference in row 2: D3, D99, Cell: $AZ$25 Not found in row: 3 Not found in row: 4 If it's not working, then please make an example or post your code so that we can run it and see why it doesn't work. Just saying that it doesn't work without more information isn't helpful for us to give you a solution. Sorry, my fault it works. I just need to use the first line. Thanks,
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