Set Focus to Cell

Hello everybody,

I’m currently working on a set of macos for worksheets. I set formulars to cells etc. But funnily I’m stuck with a quite simple problem (so it seems). After processing several cells, I’d like to set the focus (activate) a particular cell.

I tried something like:

var oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange("B1:B1");

But that does not set the focus to the specified cell.

Can anybody help?

Hello @Dimpflmoser

Do you mean you’d like to select a cell or a range of cells? If yes, then for this Select method exists.

Hello Constantine,

I have already tried the select method - but nothing happens …

What my macro does is:
I first select cells from a row via GetRange and insert formulars to the cells. I then format the cells. So to the user it appears like a new input-row has been added, in which he can insert data which will be processed. What I’d like to achieve is that a certain cell in this row is activated - so the user can just start typing data into that cell. Let’s call the cell B2. But after processing the cells I use the select-method like follows (where intZeile represents the row number) the activated cell remains A2:

objRange = objTabbelle.GetRange("B" + intZeile);
objRange.Select();

Thanks again

You can use a separate object exclusively for the cell you want to select. For example:

// Initial process starts
var oWorksheet = Api.GetActiveSheet();
var oRange = oWorksheet.GetRange("A1:D1");
oRange.SetValue("Processing");
// Process has ended

// Selecting a separate cell 
var cellSelect = oWorksheet.GetRange("B2");
cellSelect.Select();

In this case after the data has been inserted according to your scenario, you can select exact cell with Select method. Isn’t that you are trying to achieve?