Jump to content

Excel Range usage with Cells [solved]


UEZ
 Share

Recommended Posts

I'm stuck on how to use for range selection .Cells function.

Instead of

_Excel_RangeSort($oWorkbook, Default, Default, "AD:AD", Default, Default, $xlYes, False, Default, "AE:AE", Default, "L:L", Default)

and

$aResult = _Excel_RangeRead($oWorkbook, 1, "S2:AB" & $iRows)

which works properly I want to use Cells to select the range.

 

Why? Because the Excel sheet was modified and an additional row was inserted. I want to create the script more dynamically by selection it with Cells because I can search for the column headers.

Any idea?

 

Thanks.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

$oWorkbook.ActiveSheet.Cells(x,y)
In the wiki you'll find a page where some special ranges are described.

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

Thanks water!

$aResult = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Range($oWorkbook.ActiveSheet.Cells(2, 18), $oWorkbook.ActiveSheet.Cells($iRows, 27)))

works for this particular line.

Does it works the same way also for _Excel_RangeSort?

 

Btw, is should be $oWorkbook.ActiveSheet.Cells(y,x)! ;)

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

All _Excel* functions accept a range object or an "A1" notation.
The following properties and methods return a range:


 

Edited by water

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

Thanks water, I got it worked now.

;before
_Excel_RangeSort($oWorkbook, Default, Default, "AD:AD", Default, Default, $xlYes, False, Default, "AE:AE", Default, "L:L", Default)

;after
_Excel_RangeSort($oWorkbook, Default, Default, _
    $oWorkbook.ActiveSheet.Range($oWorkbook.ActiveSheet.Cells(2, $iPos_Shelf + 1), $oWorkbook.ActiveSheet.Cells($iRows, $iPos_Shelf + 1)), Default, Default, $xlYes, False, Default, _
    $oWorkbook.ActiveSheet.Range($oWorkbook.ActiveSheet.Cells(2, $iPos_Slot + 1), $oWorkbook.ActiveSheet.Cells($iRows, $iPos_Slot + 1)), Default, _
    $oWorkbook.ActiveSheet.Range($oWorkbook.ActiveSheet.Cells(2, $iPos_ModelType + 1), $oWorkbook.ActiveSheet.Cells($iRows, $iPos_ModelType + 1)), Default)



;before
$aResult = _Excel_RangeRead($oWorkbook, 1, "S2:AB" & $iRows)

;after
$aResult = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Range( _
                            $oWorkbook.ActiveSheet.Cells(2, $iPos_Region + 1), _
                            $oWorkbook.ActiveSheet.Cells($iRows, $iPos_GN + 1)))

 

Outlook issue still ongoing... :think:

 

Edit:

_Excel_RangeSort($oWorkbook, Default, Default, _
    $oWorkbook.ActiveSheet.Range($oWorkbook.ActiveSheet.Cells(2, $iPos_Shelf + 1), $oWorkbook.ActiveSheet.Cells($iRows, $iPos_Shelf + 1)), Default, Default, $xlYes, False, Default, _
    $oWorkbook.ActiveSheet.Range($oWorkbook.ActiveSheet.Cells(2, $iPos_Slot + 1), $oWorkbook.ActiveSheet.Cells($iRows, $iPos_Slot + 1)), Default, _
    $oWorkbook.ActiveSheet.Range($oWorkbook.ActiveSheet.Cells(2, $iPos_ModelType + 1), $oWorkbook.ActiveSheet.Cells($iRows, $iPos_ModelType + 1)), Default)

doesn't work properly. The transformation e.g. of "AD:AD" seems to be different.

Workaround:

$oMatch = $oWorkbook.ActiveSheet.Range("A1:ZA1").Find("Shelf", Default, $xlValues, $xlPart, Default, Default, False)
$sPos_Shelf = StringRegExpReplace($oMatch.Address, "\$(.+)\$\d*", "$1")
$oMatch = Null
$oMatch = $oWorkbook.ActiveSheet.Range("A1:ZA1").Find("Slot", Default, $xlValues, $xlPart, Default, Default, False)
$sPos_Slot = StringRegExpReplace($oMatch.Address, "\$(.+)\$\d*", "$1")
$oMatch = Null
$oMatch = $oWorkbook.ActiveSheet.Range("A1:ZA1").Find("Model Type", Default, $xlValues, $xlPart, Default, Default, False)
$sPos_ModelType = StringRegExpReplace($oMatch.Address, "\$(.+)\$\d*", "$1")
$oMatch = Null

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Glad you got it working :)

The Outlook issue is still on my ToDo-List but I'm quite busy at the moment. Can only spend a few minutes to answer some threads but do not have the time to check your problem at the moment.
Will keep you informed.

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