Jump to content

_Excel_RangeFind() and empty search


Go to solution Solved by MWIProd,

Recommended Posts

 

#include <Array.au3>

Local $oExcel = ObjCreate("Excel.Application") ; Create an Excel Object

;Example data *****************************
$oExcel.Visible = 1 ; Let Excel show itself
$oExcel.WorkBooks.Add ; Add a new workbook
Local $aArray[16][16]
For $i = 0 To 15
    For $j = 0 To 15
        $aArray[$i][$j] = (Random(0, 10, 1) > 0) ? (Random(100, 1000, 1)) : ("")
    Next
Next
;~ _ArrayDisplay($aArray)
$oExcel.activesheet.range("A1:O16").value = $aArray ; Fill cells with example numbers
Sleep(2000) ; Wait a while before continuing
;******************************************

Local $aEmpty = [0]
For $iCell In $oExcel.ActiveSheet.Range("A1:O16")
    If $iCell.Value = "" Then
        ReDim $aEmpty[UBound($aEmpty) + 1]
        $aEmpty[0] += 1
        $aEmpty[$aEmpty[0]] = $iCell.Address
    EndIf
Next
_ArrayDisplay($aEmpty)

 

I know that I know nothing

Link to comment
Share on other sites

A bit of a different approach :

#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\_Excel1.xls")
Local $oRange = $oWorkbook.Sheets(1).Range("A1:K7")
Local $oList = $oRange.SpecialCells($xlCellTypeBlanks)
ConsoleWrite($oList.count & " empty cells found" & @CRLF)
For $oCell In $oList
  ConsoleWrite($oCell.Address & @CRLF)
Next
$oList.value = "<<Empty>>"

 

Link to comment
Share on other sites

More special ranges can be found in the wiki.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

  • 2 months later...
Posted (edited)

Thank you all for your answers.

I tried Nine code but it doesn't work for me.

In fact my sheet contains fusionned cells (col E & F).

So If I want to search empty cells in E:F, results are ALL cells in E:F 😞

#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\_Excel1.xls")
Local $oRange = $oWorkbook.Sheets(1).Range("E:F")
Local $oList = $oRange.SpecialCells($xlCellTypeBlanks)
ConsoleWrite($oList.count & " empty cells found" & @CRLF)
For $oCell In $oList
  ConsoleWrite($oCell.Address & @CRLF)
Next
Results :

$E$1
$F$1
$E$2
$F$2
$E$3
$F$3
$E$4
$F$4
$E$5
$F$5
$E$6
$F$6
$E$7
$F$7
$E$8
$F$8
$E$9
$F$9
$E$10
$F$10
Edited by MWIProd
Link to comment
Share on other sites

  • Developers
Posted (edited)

Your range definition is not correct and requires a row number for both columns:

#include <Excel.au3>
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\_Excel1.xls")
Local $oRange = $oWorkbook.Sheets(1).Range("E1:F20")
Local $oList = $oRange.SpecialCells($xlCellTypeBlanks)
ConsoleWrite($oList.count & " empty cells found" & @CRLF)
For $oCell In $oList
  ConsoleWrite($oCell.Address & @CRLF)
Next
_Excel_BookClose($oWorkbook)

image.png.c81e409201832977b1b28d2b26684ff8.png

4 empty cells found
$E$6
$E$9
$F$9
$F$13

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The cells from col E and F are merged.

I am sorry, I used word "fusionned". 😞

image.png.cbd51d4b09094c80ca09fbe7b9fb06b3.png

So with this code (and without row number) I can list all cell with string 'zzzzzzzz' :

Local $aResult = _Excel_RangeFind($oWorkbook, 'zzzzzzzz', 'E:F', Default, $xlWhole)

With your code, all merged cells are listed.

If I merge cells A1, B1 and C1, $A$1, $B$1 and $C$1 are listed.

Link to comment
Share on other sites

You may need to unmerge the "fusionned" cells before :

...
Local $oRange = $oWorkbook.Sheets(1).Range("E:F")
$oRange.UnMerge()
Local $oList = $oRange.SpecialCells($xlCellTypeBlanks)
...

untested (too old ms-excel)

Link to comment
Share on other sites

Technically Column F is empty, only Column E contains the data. Try one column at a time. And skip the second column of merged cells.

1.png.85df3ad38732d5e066427b926838978a.png

Quote

2 empty cells found
$E$5
$F$5

 

Local $oRange = $oWorkbook.Sheets(1).Range("E:E")
Local $oList = $oRange.SpecialCells($xlCellTypeBlanks)

 

Edited by donnyh13

LibreOffice UDF  ; Scite4AutoIt Spell-Checker Using LibreOffice

Spoiler

"Life is chiefly made up, not of great sacrifices and wonderful achievements, but of little things. It is oftenest through the little things which seem so unworthy of notice that great good or evil is brought into our lives. It is through our failure to endure the tests that come to us in little things, that the habits are molded, the character misshaped; and when the greater tests come, they find us unready. Only by acting upon principle in the tests of daily life can we acquire power to stand firm and faithful in the most dangerous and most difficult positions."

 

Link to comment
Share on other sites

  • Solution

It works !

Many thanks to all of you. 🙂

Local $oRange = $oWorkbook.Sheets(1).Range("E:F")
$oRange.UnMerge()
$oRange = $oWorkbook.Sheets(1).Range("E:E")
Local $oList = $oRange.SpecialCells($xlCellTypeBlanks)
ConsoleWrite($oList.count & " empty cells found" & @CRLF)
For $oCell In $oList
  ConsoleWrite($oCell.Address & @CRLF)
Next

 

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