kctvt

How to know max number in Excel

7 posts in this topic

Hi there, i'm looking for a script to take max number of a column in Excel.

 

Ex :  Column C , i have : 

12

13

22

123

154

....

.....

.....

134534

(About 134600 rows)


So, How to know which is the max number in Column C.

I have this code, but it take me a lot of time >"< 

So... please help me a faster code.

 

$x = 3

$CloseCheck1 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+1)
$CloseCheck2 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+2)
$CloseCheck3 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+3)
$CloseCheck4 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+4)
$CloseCheck5 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+5)
$CloseCheck6 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+6)
$CloseCheck7 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+7)
$CloseCheck8 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+8)
$CloseCheck9 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+9)
$CloseCheck10 = _Excel_RangeRead($oWorkbook, Default, "C"&$x+10)

Local $aArray = StringSplit($CloseCheck1&","&$CloseCheck2&","&$CloseCheck3&","&$CloseCheck4&","&$CloseCheck5&","&$CloseCheck6&","&$CloseCheck7&","&$CloseCheck8&","&$CloseCheck9&","&$CloseCheck10,",")
$DMAX = _ArrayMax($aArray, 1, 1)
$DMIN = _ArrayMin($aArray, 1, 1)

$n = 11
While 1
$CloseCheckn = _Excel_RangeRead($oWorkbook, Default, "C"&$x+n)

If $CloseCheckn > $DMAX Then
Global $DMAX = $CloseCheckn
EndIf

If $CloseCheckn < $DMIN Then
Global $MIN = $CloseCheckn
EndIf

If $CloseCheckn = "" Then
   ExitLoop
EndIf

$n = $n + 1
WEnd

_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $DMAX, "P1")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $DMIN, "P2")

 

 

Thanks :) 

 

 

 

 

Share this post


Link to post
Share on other sites



7 minutes ago, Anoop said:

Take the data in an array using 

_Excel_RangeRead

and use 

_ArrayMax

to find the highest value.

 

 

Thank Anoop, I try, but it dont work. This is my code : 

Global $oAppl = _Excel_Open()
Global $sWorkbook1 = @ScriptDir & "\Test.xls"
Global $oWorkbook1 = _Excel_BookOpen($oAppl, $sWorkbook1, Default, Default, True)

$aResult = _Excel_RangeRead($oWorkbook1, 2, "F1:F39", 1)
$max = _ArrayMax($aResult, 0, 1)
MsgBox($MB_SYSTEMMODAL, "","$max  is : " & $max)

 

 

 

 

Share this post


Link to post
Share on other sites
#include <Excel.au3>
#include <Array.au3>

Global $oAppl = _Excel_Open()
Global $sWorkbook1 = @ScriptDir & "\Test.xls"
Global $oWorkbook1 = _Excel_BookOpen($oAppl, $sWorkbook1, Default, Default, True)

$aResult = _Excel_RangeRead($oWorkbook1)
_ArrayDisplay ($aResult)
$max = _ArrayMax($aResult, 1)
MsgBox($MB_SYSTEMMODAL, "","$max  is : " & $max)

Please try with this. Check if array displayed correctly.

1 person likes this

Share this post


Link to post
Share on other sites

Sorry,... my mistake .   

The code is worked. 

This is my errors :3 

"$aResult = _Excel_RangeRead($oWorkbook1, $oWorkbook1.Activesheet, "F1:F39", 1)|"
 

 

 

Global $oAppl = _Excel_Open()
Global $sWorkbook1 = @ScriptDir & "\Test.xls"
Global $oWorkbook1 = _Excel_BookOpen($oAppl, $sWorkbook1, Default, Default, True)

$aResult = _Excel_RangeRead($oWorkbook1, $oWorkbook1.Activesheet, "F1:F39", 1)
$max = _ArrayMax($aResult, 0, 1)
MsgBox($MB_SYSTEMMODAL, "","$max  is : " & $max)

 

So... Thank so much Anoop

 

 

Share this post


Link to post
Share on other sites

Or you could let Excel calculate the max value:

Global $oAppl = _Excel_Open()
Global $sWorkbook1 = @ScriptDir & "\Test.xls"
Global $oWorkbook1 = _Excel_BookOpen($oAppl, $sWorkbook1, Default, Default, True)
_Excel_RangeWrite($oWorkbook1, $oWorkbook1.Activesheet, "=MAX(F:F)", "A1", False) ; Modify the target "A1" range if needed
$iMax = _Excel_RangeRead($oWorkbook1, $oWorkbook1.Activesheet, "A1", 1) ; Modify the source "A1" range if needed
MsgBox($MB_SYSTEMMODAL, "","$iMax  is : " & $iMax)
_Excel_BookClose($oWorkbook1, False) ; Close book without saving

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-02-03 - Version 1.4.7.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-03 - Version 1.2.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
30 minutes ago, water said:

Or you could let Excel calculate the max value:

Global $oAppl = _Excel_Open()
Global $sWorkbook1 = @ScriptDir & "\Test.xls"
Global $oWorkbook1 = _Excel_BookOpen($oAppl, $sWorkbook1, Default, Default, True)
_Excel_RangeWrite($oWorkbook1, $oWorkbook1.Activesheet, "=MAX(F:F)", "A1", False) ; Modify the target "A1" range if needed
$iMax = _Excel_RangeRead($oWorkbook1, $oWorkbook1.Activesheet, "A1", 1) ; Modify the source "A1" range if needed
MsgBox($MB_SYSTEMMODAL, "","$iMax  is : " & $iMax)
_Excel_BookClose($oWorkbook1, False) ; Close book without saving

 

Thank Water :) 

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

  • Similar Content

    • Paranthaman
      By Paranthaman
      Hi Everyone,
      I am a beginner and I am currently learning and practicing what Autoit can do, so kindly pardon if it sound's silly.
      What my program does ----> I had written a program where I have a FOR (i=0 to n) loop which is running for n times. Inside the FOR loop, contents of array is written into excel using _Excel_RangeWrite .
      _Excel_RangeWrite($oExcelDoc, $oExcelDoc.Activesheet, $arrayname, "A1") Problem ------> During every loop run the contents of column A is only altered
      What i intend to do ------> For every loop run (i=0,1,2,3...) I want to write the array contents into respective next adjacent excel columns
      i.e) For i=0 loop, every array content should be written in A Column of excel
      For i = 1 loop, every array content should be written in B Column of excel.
       
      Can anyone give me an idea of  how can i do this? Thanks 
    • SkysLastChance
      By SkysLastChance
      Why is my code not writing X in cell D1? 
      #include <Excel.au3> Global $r = 1,$oExcel Excel () Func Excel() While ProcessExists("EXCEL.EXE") $ms = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") If $ms=2 Then Exit WEnd Local $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsx)") If FileExists($sExcelFile) Then $oExcel = _Excel_Open () $oWorkbook = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file. Else $oExcel = _Excel_Open() $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist. EndIf EndFunc Sleep (2000) _Excel_RangeWrite($oExcel,Default, "X", "D" & $r) Exit  
    • Suneel
      By Suneel
      Hi
      I want to select an excel file from a folder using selenium. The file name includes the data stamp. But, only that file will be existing in the folder. How to do it please help with the code
    • SkysLastChance
      By SkysLastChance
      I was wondering if it is possible to make this code skip to the next row if it reads a blank line?
      I tried this.
      If $aArray = "" Then $r += 1 EndIf #include <Excel.au3> Local $r = 1 Local $aArray = _Excel_RangeRead($oWorkbook) ;~ If $iBox is greater than no. of rows in $aArray then $iBox equals the number of rows in $aArray If $iBox > (UBound($aArray) - 1) Then $iBox = UBound($aArray) - 1 For $i = 1 To UBound($aArray) - 1 ;$i =0 Start from row A If $aArray = "" Then $r += 1 EndIf $sR0 = $aArray[$i][0] ;status $sR1 = $aArray[$i][1] ;first name $sR2 = $aArray[$i][2] ;Last name $sR3 = $aArray[$i][3] ;Last 4 SSN $sR4 = $aArray[$i][4] ;DOB $sR5 = $aArray[$i][5] ;Email Address $sR6 = $aArray[$i][6] ;Mailling Address $sR7 = $aArray[$i][7] ;City $sR8 = $aArray[$i][8] ;state $sR9 = $aArray[$i][9] ;Zip Code $sR10 = $aArray[$i][10] ;Gender $sR11 = $aArray[$i][11] ;Phone WinSetState ("ADM.MCK - Registration Management Desktop","",@SW_MAXIMIZE) WinWaitActive("[CLASS:Notepad]", "", 10) ControlSend("[CLASS:Notepad]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:Notepad]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:Notepad]", "", "", ("N")) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (3000) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR1 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR2 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR6& @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR7 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR8 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR9 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR11& @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR5 & @CR) ;Email Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR5 & @CR) ;Email Sleep (200) ControlSend("[CLASS:Notepad]", "", "", (FormatDate($sR4) & @CR)) $r += 1  
       
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I've been using Excel UDF for a while, and I always wanted to post this question:
      "Why, everytime I set the paramter $bVisible = False of the _Excel_Open() function, IF I HAVE AN EXCEL SHEET OPENED, I still can see the Excel opening and doing what I wrote in the script? And, in this case, how can I avoid this?"
      Thanks