Sign in to follow this  
Followers 0
FMS

Excel compare project

12 posts in this topic

Hello forrumers :oops:

I've a little problem and i hope u can help me whit a little problem.

There is a excel file whit 2 long rows and 2 tabs.

something like this:

tab1-------------

row1-----row2

M1234--45874

M7896--48656

tab2

row1-------row2

M1234---(empty)

M7896---48659

I was hoping to compare these 2 tabs whit 1 script.

search (tab 1 row 1 cel 1 ) in (tab 2 row 1) if found fil (tab 1 row 2 cel 1 ) in (tab 2 row 2 cel 1) and make cel green

search(tab 1 row 1 cel 2 ) in (tab 2 row 1) if found fil (tab 1 row 2 cel 2 ) in (tab 2 row 2 cel 2) and make cel green

iff not found make (tab 2 row 2 cel 2) red

until (tab1 row 1 cel ?) is empty

What i have this far is :

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Excel comparer", 649, 219, 192, 114)
$Input1 = GUICtrlCreateInput("Input1", 64, 24, 121, 21)
$Label1 = GUICtrlCreateLabel("C:\", 16, 24, 19, 17)
$Label2 = GUICtrlCreateLabel("Compare row", 16, 96, 66, 17)
$Input2 = GUICtrlCreateInput("Input2", 104, 88, 121, 21)
$Input3 = GUICtrlCreateInput("Input3", 104, 120, 121, 21)
$Label3 = GUICtrlCreateLabel("Fill row", 16, 120, 36, 17)
$Button1 = GUICtrlCreateButton("Run", 208, 176, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Cancel", 304, 176, 75, 25, $WS_GROUP)
$Radio1 = GUICtrlCreateRadio("C:\", 240, 24, 41, 17)
$Radio2 = GUICtrlCreateRadio("D:\", 288, 24, 41, 17)
$Group1 = GUICtrlCreateGroup("Location", 8, 8, 609, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Input4 = GUICtrlCreateInput("Input4", 280, 88, 121, 21)
$Label4 = GUICtrlCreateLabel("with", 248, 88, 23, 17)
$Label5 = GUICtrlCreateLabel("with", 248, 120, 23, 17)
$Input5 = GUICtrlCreateInput("Input5", 280, 120, 121, 21)
$Label6 = GUICtrlCreateLabel("from tab", 416, 88, 42, 17)
$Label7 = GUICtrlCreateLabel("from tab", 412, 121, 42, 17)
$Input6 = GUICtrlCreateInput("Input6", 472, 88, 121, 21)
$Input7 = GUICtrlCreateInput("Input7", 472, 120, 121, 21)
$Group2 = GUICtrlCreateGroup("Group2", 8, 72, 609, 81)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

as you can see i prety new in autoit vs excel.

I hope there is somebody that can help me whit this :bye:

Greez FMS


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I fear you are mixing things up a bit. Should it be "column" where you use "row"?

I made a screenshot how I think the both tabs look before the script has been run. If I'm correct, can you please post how the

tabs should look after the script has been run?

Tab 1:

Tab 2:

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

sorry , it's indeed colum (dutch translation;))

but in the end tab 1 and tab 2 must show the same results (maybe in a difrent order)

tab 2 has then the green or red fillings if the first cel isn't found in the other tab....

is this helpfull?


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Do tab1 and tab2 have the same number of rows (so there is no need to insert a row into tab2)?

Are tab1 and tab2 sorted the same way? So cell A17 in tab1 has the same content on tab2?

If yes, do the rows in tab1 and tab2 only differ in column 2?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

maybe this helps even more :oops:

because i dint understand what u where saying... (sorry for that)

pic1.bmp

pic2.bmp

tab2.bmp


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Quick & Dirty. This assumes that tab1 and tab2 have the same number of rows with the same content in column 1.

If this isn't true some more logic will be needed.

#include <Excel.au3>
Global $sNameTab1 = "Tab1"
Global $sNameTab2 = "Tab2"
Global $oExcel = _ExcelBookOpen("C:temptest.xls")
_ExcelSheetActivate($oExcel, $sNameTab1)
$oExcel.ActiveSheet.UsedRange.Select
Global $iMaxCell = $oExcel.ActiveSheet.UsedRange.Rows.Count
For $i = 1 To $iMaxCell
    $vTab1C1 = _ExcelReadCell($oExcel, $i, 1)
    $vTab1C2 = _ExcelReadCell($oExcel, $i, 2)
    $vTab2C1 = $oExcel.Sheets($sNameTab2).Cells($i, 1).Value
    If $vTab1C1 = $vTab2C1 Then
        $oExcel.Sheets($sNameTab2).Cells($i, 2).Value = $vTab1C2
        $oExcel.Sheets($sNameTab2).Cells($i, 2).Interior.ColorIndex = 4
    Else
        $oExcel.Sheets($sNameTab2).Cells($i, 1).Value = $vTab1C1
        $oExcel.Sheets($sNameTab2).Cells($i, 2).Value = $vTab1C2
        $oExcel.Sheets($sNameTab2).Cells($i, 2).Interior.ColorIndex = 3
    Endif
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

aaa now i understand u whit same number of row's....

thnx for your reply it is realy helpful to understand the excel import.

but here's the thing :oops:

they are not the same :bye:

i was hoping that the script could look up

(colum 1 cel 1 of tab 1) in (tab 2 colum 1) en put cel if found of (colum 1 cel 2 of tab 1) in (colum 2 of (found cel ) tab 2)

if not found goto colum 1 cel 2 of tab 1 and search again until no text in colum 1 of tab 1.

does this make any sence?

i realy hope so because i dont know how to explain it:(


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

OK, got it.

I will post an example quite soon.

Edit:

About how many rows (lines) to we talk in tab1 and tab2?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This works (at least for me):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Excel.au3>
#include <Array.au3>
Global $vTab1C1, $vTab1C2, $bFound = False
Global $sNameTab1 = "Tab1"                                                          ; Name of the first tab
Global $sNameTab2 = "Tab2"                                                          ; Name of the second tab
Global $oExcel = _ExcelBookOpen("C:temptest.xls")                                   ; Open the Excel Workbook
Global $iMaxRowTab1 = $oExcel.Sheets($sNameTab1).UsedRange.Rows.Count               ; Maximum rows of tab1
Global $iMaxRowTab2 = $oExcel.Sheets($sNameTab2).UsedRange.Rows.Count               ; Maximum rows of tab2
_ExcelSheetActivate($oExcel, $sNameTab2)                                            ; Activate tab2
Global $aRowsTab2 = _ExcelReadArray($oExcel, 1, 1, $iMaxRowTab2, 1, 1)              ; Read all entries in column 1 into an array
_ExcelSheetActivate($oExcel, $sNameTab1)                                            ; Activate tab1
For $i = 1 To $iMaxRowTab1                                                          ; Loop through all rows on tab1
    $vTab1C1 = _ExcelReadCell($oExcel, $i, 1)                                       ; Read column 1 of the current row
    $vTab1C2 = _ExcelReadCell($oExcel, $i, 2)                                       ; Read column 2 of the current row
    $bFound = False                                                                 ; Set flag
    For $j = 1 To $aRowsTab2[0]                                                     ; Search for the entry
        If $vTab1C1 = $aRowsTab2[$j] Then                                           ; IF found set the flag and exit the loop
            $bFound = True
            ExitLoop
        EndIf
    Next
    If $bFound Then                                                                 ; If found set column 2 of tab2 to the value of column 2 of tab1
        $oExcel.Sheets($sNameTab2).Cells($j, 2).Value = $vTab1C2
        $oExcel.Sheets($sNameTab2).Cells($j, 2).Interior.ColorIndex = 4             ; Set color
    Else
        $iMaxRowTab2 = $iMaxRowTab2 + 1                                             ; Add index of first free row in tab2
        $oExcel.Sheets($sNameTab2).Cells($iMaxRowTab2, 1).Value = $vTab1C1          ; add record of tab1 to tab2
        $oExcel.Sheets($sNameTab2).Cells($iMaxRowTab2, 2).Value = $vTab1C2
        $oExcel.Sheets($sNameTab2).Cells($iMaxRowTab2, 2).Interior.ColorIndex = 3   ; Set color
    Endif
Next

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

NICE TOTALY WHAT I NEEDED!!!!!

i very greatfull :oops:

also its very understandeble because the info u put ad the end of the centence :bye:

from this i can learn a lot:) and is easyer to expand the scripting or custamazation.

thank u very very mush....

greez FMS


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Glad to be of service :oops:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I enhanced the script a bit so it is now independant of the name of the tabs (it uses the shett numbers instead):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Excel.au3>
#include <Array.au3>
Global $vTab1C1, $vTab1C2, $bFound = False
Global $oExcel = _ExcelBookOpen("C:temptest.xls")                           ; Open the Excel Workbook
Global $iMaxRowTab1 = $oExcel.Sheets(1).UsedRange.Rows.Count                ; Maximum rows of tab1
Global $iMaxRowTab2 = $oExcel.Sheets(2).UsedRange.Rows.Count                ; Maximum rows of tab2
_ExcelSheetActivate($oExcel, 2)                                             ; Activate tab2
Global $aRowsTab2 = _ExcelReadArray($oExcel, 1, 1, $iMaxRowTab2, 1, 1)      ; Read all entries in column 1 into an array
_ExcelSheetActivate($oExcel, 1)                                             ; Activate tab1
For $i = 1 To $iMaxRowTab1                                                  ; Loop through all rows on tab1
    $vTab1C1 = _ExcelReadCell($oExcel, $i, 1)                               ; Read column 1 of the current row
    $vTab1C2 = _ExcelReadCell($oExcel, $i, 2)                               ; Read column 2 of the current row
    $bFound = False                                                         ; Set flag
    For $j = 1 To $aRowsTab2[0]                                             ; Search for the entry
        If $vTab1C1 = $aRowsTab2[$j] Then                                   ; If found set the flag and exit the loop
            $bFound = True
            ExitLoop
        EndIf
    Next
    If $bFound Then                                                         ; If found set column 2 of tab2 to the value of column 2 of tab1
        $oExcel.Sheets(2).Cells($j, 2).Value = $vTab1C2
        $oExcel.Sheets(2).Cells($j, 2).Interior.ColorIndex = 4              ; Set color
    Else
        $iMaxRowTab2 = $iMaxRowTab2 + 1                                     ; Add index of first free row in tab2
        $oExcel.Sheets(2).Cells($iMaxRowTab2, 1).Value = $vTab1C1           ; add record of tab1 to tab2
        $oExcel.Sheets(2).Cells($iMaxRowTab2, 2).Value = $vTab1C2
        $oExcel.Sheets(2).Cells($iMaxRowTab2, 2).Interior.ColorIndex = 3    ; Set color
    Endif
Next
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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
Sign in to follow this  
Followers 0