Jump to content
vick

array unique from excel

Recommended Posts

vick

Hi All,

To get unique value from column i use below code but it si not working. can you tell me where i am wrong pls?

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")


$bat = _Excel_RangeRead($oWorkbook,1,"AY3:AY7")
_ArrayDisplay($bat)
$d = _ArrayUnique($bat)
_ArrayDisplay($d)

thanks,

Share this post


Link to post
Share on other sites
water

Here it works as designed :)
Be aware that  your code returns the row count in line 0 of the array.
To drop the row count use:

$d = _ArrayUnique($bat, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vick

Hi,

 

I have attached screenshots of what i did and what i am getting. still not getting unique.

 

000426.png

000427.png

000428.png

Share this post


Link to post
Share on other sites
water

Whats the value of @error after _ArrayUnique?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

BTW: Which version of AutoIt do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vick

@error shows 0. version of Autoit is v3.3.14.2

Share this post


Link to post
Share on other sites
water

I have run out of ideas :(


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
spudw2k
water
Posted (edited)

Can you please provide the Excel file so we can play with it?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vick

i uploaded file. But if i put same worksheet numbers in array manually and then use _Arrayunique then it works so when i read from excel has something wrong i guess.

TEST1.xlsx

Share this post


Link to post
Share on other sites
water

Your example works here as expected.
In your original post you were talking about cells AY3:AY7. How did you move them to A3:A7?

I suspect that the cells contain some unreadable/undisplayable characters so _ArrayUnique gets into troubles.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vick

i remove all other columns to make it simple.

is it possible because of too many data in excel?

can you send me pls same code you executed so i can try same one?

Share this post


Link to post
Share on other sites
Juvigy
Posted (edited)

I have the same issue as the user.

And this code works as expected for me:

$oExcel = ObjGet("", "Excel.Application")
$array = $oExcel.Application.Selection.Value
$array = _ArrayToString($array,"|","|")
ConsoleWrite($array&@CRLF)
$array = StringSplit($array,"|")
_ArrayDisplay($array)
$d = _ArrayUnique($array)
_ArrayDisplay($d)

 

Edited by Juvigy
added code

Share this post


Link to post
Share on other sites
water
Posted (edited)

@juvigy
You use the test workbook test1.xslx that the user posted today?
You select columns A3:A7 and then run your script?

BTW: Which version of AutoIt do you run? Parameter 3 of _ArrayToString is expected to be a numeric value in AutoIt 3.3.14.4 (but it doesn't make a difference).

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vick

surprisingly this code works but after arrayunique count is showing original one not after unique .

i observed this script convert first array to string and then from string to array. then it works. still something missing in logic of arrayunique function.

thanks,

Share this post


Link to post
Share on other sites
water

How to drop the post count please check post #2 in  this thread.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vick

even i use $ARRAYUNIQUE_NOCOUNT still it shows. i guess it takes  count as one of array element that's why it even not changing.

000429.png

000430.png

Share this post


Link to post
Share on other sites
vick

thank you very much both  @Juvigy and @water for your support.

Share this post


Link to post
Share on other sites
water

Use stringsplit this way:

$array = StringSplit($array,"|", $STR_NOCOUNT)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vick

perfect!! it works. thanks

Share this post


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

×