Jump to content

Is there an equivalent of "Match" function in Excel?


Recommended Posts

Hi,

I'm sorry, english isn't my mother tongue, so I tried to look in the forum to answer my question, but did'nt find...

I have a large array (60 columns X 100 lines) first line is the questions, and all the following datas in the same column is the answer. Let's say that a question is in column 3, Then I do an _ArrayExctrat from column 3 and give a new name to that array related to the question. But in the future, the questions (and the following answer below) might move and be in column 5 or 10. So if I do an array extract of column 3 it won't work anymore.

I found a way using while loop (while the name of the column is not what I'm looking for, grow a iteration by 1 and then this iteration is the number of my column) 

But making a while loop for all my 60 questions is long to do and takes a lot of line code!

Is there a way to be more efficient? In Excel, there is this MATCH function 

           A                     B                   C

1   Fisrt name   Last name   date of birth

2    Mathieu       Laplante        may, 4th 1980

3    Ginette         Paré              oct, 10th, 1974

 

=match("Last Name";A1:C1) wil give me 2 as an answer...

 

Thanks a lot!!

 

 

 

 

 

 

Link to comment
Share on other sites

The loop is probably most effective and it does not "take a lot of line of code" (it probably takes less lines than my example).  That aside, pulling this off without a loop sounded like fun

this assumes you have read your excel file to an array that looks like the one in the OP:

#include<array.au3>

local $a[3][4] = [["1" , "First name" , "Last name" , "date of birth"],["2", "Mathieu" , "Laplante" , "may, 4th 1980"],["3" ,  "Ginette" ,  "Pare" , "oct, 10th, 1974"]]

_ArrayTranspose($a)
msgbox(0 , '' , _ArraySearch($a , "Last name"))

 

edit:  wait wth, you only need the column that appears in (or do you need need row and column like a jeopardy board)?  How did you know it was in row 1 to search a1-c1? 

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Another, more efficient way: create two arrays.

The first lists the questions and their index in the data array column number.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Amazing !!!  _ArraySearch AND _ArrayTranspose before!!!!!

 

Thank you so much!!!

 

But tell me... How would you have used while loop and be more efficient? Cause I was planning to do this code for every single questions... (40 times!) $aRetArray is my main array, $Question is the first line of this array. Once $iteration is on the question "You Are :", I get my column number...

$iteration = 0

while $Question[0][$iteration] <> "You are : "
    $iteration = $iteration+1
WEnd
Global $ResidentStatus = _arrayextract($aretarray,0,100,$iteration,$iteration)
$iteration = 0


 

 

Link to comment
Share on other sites

I dont know if this is a legit usage of exitloop (that since I dont care about the level i am exiting just doing something else there instead).

but this is the quickest I can play the match game

#include<array.au3>

local $a[3][4] = [["1" , "First name" , "Last name" , "date of birth"],["2", "Mathieu" , "Laplante" , "may, 4th 1980"],["3" ,  "Ginette" ,  "Pare" , "oct, 10th, 1974"]]

;~ $sSearch= "2"
;~ $sSearch = "Mathieu"
;~ $sSearch = "Pare"
$sSearch = "nomatch"

$result = "not found"

for $i = 0 to ubound($a) - 1
If _ArraySearch($a , $sSearch , 0 , 0 , 0 , 0 , 0, $i) > -1 then exitloop(assign("result" , "$a[" & _ArraySearch($a , $sSearch , 0 , 0 , 0, 0, $i) & "][" & $i & "]"))
next

msgbox(0, '' , $result)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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