Ask a Question

How to select Excel cells by cell name (ex: E5, B10..)?

Occasional Contributor

How to select Excel cells by cell name (ex: E5, B10..)?

Trying to select required cells in Excel using TestComplete, and it locates them by position on the screen:

#Clicks the 'Book1' object.
Aliases.EXCEL.wndXLMAIN.XLDESK.Book1.Click(264, 131)
#Clicks the 'Book1' object.
Aliases.EXCEL.wndXLMAIN.XLDESK.Book1.Click(69, 248)


Is there a way to locate them by their name (ex: E5, B10..)?

Community Hero

To select cells use Range

let range1 = excelMainSheet.Range(excelMainSheet.Cells.Item(4, 8), excelMainSheet.Cells.Item(5, 9));


To select individually use Cells.Item(L,C)

Cells.Item can be used in both syntax Row and Col index  or Row and Col name

For example this put in cell J4 the address of itself (here $J$4),  you see that i use both syntax.

excelMainSheet.Cells.Item("4","J").Value2 = excelMainSheet.Cells.Item(4, 10).Address();


Here excelMainSheet is your active sheet.


Un sourire et ça repart

Occasional Contributor

Tried that but getting "Unable to find the object Cells" error


here is my code: 


def Test1():
#Runs the "EXCEL" tested application.
TestedApps.EXCEL.Run(1, True)
#Maximizes the 'wndXLMAIN' window.
OCR.Recognize(Aliases.EXCEL.wndXLMAIN.FullpageUIHost.NetUIHWND).BlockByText("Blank workbook").Click()
#Clicks the 'Book1' object.

Esteemed Contributor


May I ask why you're using the UI of Excel to automate manipulating an Excel workbook/spreadsheet?

You can do a LOT more without having to mess around with identifying ribbon controls, onscreen objects, etc., but simply instantiating an Excel.Application object using Sys.OleObject and utilizing the methods and properties of Excel, Excel Workbooks, and Excel Sheets directly without having to work with the UI at all.

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Occasional Contributor

Of course, the goal is to test company specific Excel Add ins, for example simple scenario:

user opens Excel, create some table using our specific Add in, imports that table, and then gets that table in our app

My solution was using COMobject and not gui so it wont work directly like that in gui.


By GUI to select a cell you have just to enter its address in the highligthed edit box below :



Un sourire et ça repart

Occasional Contributor

Thank you for your responses!

Is that possible to select a range of cell using edit box?

err... Did you simply try to enter a range ?


Yes you can, e.g. type A1:B4 will select the corresponding range.


Un sourire et ça repart

Occasional Contributor

Great. Thank you!

Showing results for 
Search instead for 
Did you mean: