Jump to content

Finding Excel range address


Recommended Posts

Hi,

I have an Excel file that contains specific named range in a specific sheet.

I can read the content of the range using:

Local $RangeContent = _Excel_RangeRead($oWorkbook, "MySheetName", "MyRangeName")

The position of the range within the sheet can vary. I need to find out the position of the range (like B25 or C5 or wherever it is) so that I can pass it to other functions.

So I would need something like this:

Local $MyRangeColumn = _GET_THE_COLUMN($oWorkbook, "MySheetName", "MyRangeName")
Local $MyRangeRow = _GET_THE_ROW($oWorkbook, "MySheetName", "MyRangeName")

The range always contains only one cell (like A1), it is never larger (like A1:B3).

The problem may be that the sheet is hidden so I can't .Activate it (but the _Excel_RangeRead still works).

I was searching through the forums but I could't find anything useful, and I'm not even sure how to start.

Any help is appreciated.

Thanks,

Kaarl

Link to comment
Share on other sites

Hi,

See https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_RangeFind.htm

Edit:

I may have misunderstood, do you want to get the row/col name of a range or look for the range that contains something?

$Row= $oWorkbook.Sheets("SHEETNAME").Range("A1").Row)
$Column= _Excel_ColumnToLetter($oWorkbook.Sheets("SHEETNAME").Range("A1").Column))

 

Edited by Moonscarlet
Link to comment
Share on other sites

I need to get the row number (1, 3, 5 or whatever) and column name (A, C, BX or whatever). So if the named range is situated in cell B3 I need to get something like.

$MyRangeColumn = "B"
$MyRangeRow = 3

It doesn't really matter now whether the range has any content in it or not. Important are its coordinates, because they determine locations of other data in the sheet. My named range can be a location of a header of a column or name of a row, so I need the coordinates to read the data in the appropriate column/row.

I hope this clarifies it better. 

Link to comment
Share on other sites

I've got still a lot to learn.

Works like a charm (except the extra brackets at end that throw a syntax error).

This one works:

$Row= $oWorkbook.Sheets("SHEETNAME").Range("A1").Row
$Column= _Excel_ColumnToLetter($oWorkbook.Sheets("SHEETNAME").Range("A1").Column)

Thanks a lot for the solution!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...