Jump to content

_Excel_Rangefind issue - (Moved)


baamr
 Share

Go to solution Solved by mistersquirrle,

Recommended Posts

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

 

 

Excel_Rangefind.jpg

Edited by baamr
removed one pic
Link to comment
Share on other sites

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Solution

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 by mistersquirrle
Updated code

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

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,

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