Ask Your Question
0

Make cursor move to certain cell when "enter" key pressed?

asked 2017-09-28 19:22:26 +0200

appreciatethehelp gravatar image

Hello.

I have a calc spreadsheet that contains cells created with the intention that they be filled out in a certain order. However, due to other factors, these cells cannot be laid out in sequence/ one after another, they must remain "jumbled up".

So I wonder, is there any way to set the selected cell to "jump" to another cell once the "enter" key is pressed? For example, normally when the enter key is pressed in a spreadsheet, the cursor/highlighted cell moves down to the cell directly below it, e.g when the cell A1 is highlighted then the enter key is pressed, the selected cell becomes A2.

Instead, could I, for example, set A1 to become A5 when the enter key is pressed, or B2 to become F2 etc…?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-09-28 21:55:13 +0200

Lupp gravatar image

updated 2017-09-28 21:56:38 +0200

You will have to resort to user code. One way to do it then is, to create cell styles for the cells from which to jump elsewhere by a relative address, and to assign a 'Sub' evaluating the styles to the 'Sheet Event...' 'Content changed' for sheets you want to perform the trick.
See this attached demo.

Of course, you may also code the explicit target address soemhow in the style name. I think the way I suggested is more flexible.

edit flag offensive delete link more

Comments

Nice trick, @Lupp. Perhaps you should add at the end the line ThisComponent.CurrentController.Select(ThisComponent.createInstance("com.sun.star.sheet.SheetCellRanges")) to deselect active cell.

JohnSUN gravatar imageJohnSUN ( 2017-09-29 07:31:38 +0200 )edit

@JohnSUN: Thanks for trusting in my understanding so much. However, I am actually too dull and need additional explanation.
What is a NULL-initialised selection supposed to achieve?

Lupp gravatar imageLupp ( 2017-09-29 11:41:40 +0200 )edit

After .Select(nextCell) we jump to this nextCell and fill it (like as Click - Shift+Click). NULL-initialised selection will deselect it

JohnSUN gravatar imageJohnSUN ( 2017-09-29 16:22:53 +0200 )edit

Thanks. I didn't take this seriously and didn't look thoroughly enough. As the only selected cell in this case, nextCell will nonetheless remain (the only) part of the .CurrentSelection. An empty .CurrentSelection seems to not be allowed.

Lupp gravatar imageLupp ( 2017-09-29 17:53:03 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-09-28 19:22:26 +0200

Seen: 355 times

Last updated: Sep 28 '17