Jump to content

Excel, change values based on


Recommended Posts

Hi, what is the fastest way to do this:

Read a column in excel all the way down and change every cell value that isn't an ip adress number into a unique number.

I did a small script but took almost 15 -20  minuts to complete on a 8000 rows sheet and i had 0 sleeps in it :/

Thanx in advance

-smelly-

Link to comment
Share on other sites

If you modify the sheet cell by cell it will take forever.

Use _Excel_RangeRead from my rewrite of the Excel UDF to read the whole column in one go into an array. Then modify the array to your needs and rewrite the column using function _Excel_RangeWrite.

For download of the UDF please check my signature.

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

Seems like i can't get the Excel_RangeRead to actually read a range it just reads 1 cell or no cells at all, how would i write a range in your function?, i can create an array with the old Excel.au3 and display it, but i'm not good with manipulating arrays and not sure how to make the changes in the array before writeback, im guessing i need the opposite of regexReplace or something :/ ?

#Include <Excel.au3>
#include <Array.au3>
#include <misc.au3>
#include <string.au3>

Global $compare
Global $boo
$oExcel = _ExcelBookOpen(@ScriptDir & "\ips.xlsx",0)
$myArray = $oExcel.Activesheet.Range("C1:C600").Value

_ArrayDisplay($myArray,"","",1)

;Find all entries in array that's not an ip-adress and change to an unique value


;Write the changes to excel

_ExcelBookClose($oExcel)

Im kinda lost here, i need a simple example on how to get started, and a bible book about arrays :)

Link to comment
Share on other sites

To use my rewrite of the Excel UDF (ExcelEX) you need to download the file and include it in your script. You can't mix the Excel UDF that comes with AutoIt and my rewrite.

And you need to run the latest AutoIt beta version.

To manipulate arrays I suggest to have a look at the array tutorial in the wiki.

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

Please post the code you used with my new UDF and I will have a look.

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

#include <Excel Rewrite.au3>
#include <Array.au3>
#include <Constants.au3>

Global $oAppl = _Excel_Open()
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Trying to Read Range", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Global $oWorkbook = _Excel_BookOpen($oAppl, @ScriptDir & "\ips.xlsx")
If @error <> 0 Then
    MsgBox($MB_SYSTEMMODAL, "Trying to Open workbook", "Error opening workbook" & $oWorkbook & " " & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oAppl)
    Exit
EndIf

read($oWorkbook)

Func read($oWorkbook)

    Local $aResult = _Excel_RangeRead($oWorkbook, Default, "C1:C600", 2)
    If @error <> 0 Then Return MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Data successfully read." & @CRLF & "Please press enter to display the formulas of cells C1:C600.")
    _ArrayDisplay($aResult, "Excel UDF: _Excel_RangeRead Example 3 - Cells C1:C600")

EndFunc   ;read

Actually i did something very wrong with my old script, this works fine :), sorry for bothering , anyways im back to learning arrays now, and what if i don't know how big the range is? isn't there a way to just read the whole column C ?

Link to comment
Share on other sites

To read the whole column "C" replace "C1:C600" with "C:C".

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

I just tested with "A:A" and it worked just fine.

-2147352571 (dec) = 0x80020005 (hex) means: DISP_E_TYPEMISMATCH.

Which Excel version do you run?

I'm running Excel 2010 32 bit on Windows 7 64 bit.

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

Can you please add the following lines at the top of your script so we get detailed error information?

#include <Debug.au3>
_DebugSetup()
_DebugCOMError()

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

Debuginfo:

@@ DEBUG COM Error encountered in testarrayer.au3 (84) :
    Number          = 0x80020006 (-2147352570)
    WinDescription  = Okänt namn.
    Description     = 
    Source          = 
    HelpFile        = 
    HelpContext     = 
    LastDllError    = 0
    Retcode         = 0x00000000
@@ DEBUG COM Error encountered in testarrayer.au3 (918) :
    Number          = 0x80020005 (-2147352571)
    WinDescription  = Typmatchningsfel.
    Description     = 
    Source          = 
    HelpFile        = 
    HelpContext     = 
    LastDllError    = 0
    Retcode         = 0x00000000
>>>>>> Please close the "Report Log Window" to exit <<<<<<<

Link to comment
Share on other sites

Might be a problem with the transpose method.

Could you please give

Local $aResult = _Excel_RangeRead($oWorkbook, Default, "C1:C600", 2, True)

a try?

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

Sure thing, gives no errors and this bug report:

@@ DEBUG COM Error encountered in testarrayer.au3 (84) :
    Number          = 0x80020006 (-2147352570)
    WinDescription  = Okänt namn.
    Description     = 
    Source          = 
    HelpFile        = 
    HelpContext     = 
    LastDllError    = 0
    Retcode         = 0x00000000
>>>>>> Please close the "Report Log Window" to exit <<<<<<<
Link to comment
Share on other sites

That's fine.

This "error" is raised when the UDF tries to connect to an existing Excel instance - and there is none.

So the problem is solved now?

How do you like the speed?

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

That's great.

Most of the 11 seconds is spent in _ArrayDisplay to create the GUI.

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

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

×
×
  • Create New...