+ Reply to Thread
Results 1 to 21 of 21

Macro line to move the cursor

  1. #1
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Macro line to move the cursor

    Is there a way to include, as part of a macro, an instruction that will move THE CURSOR to another cell?
    I don’t mean going to a cell by selecting it, but, while one cell is selected, moving just the cursor to any other spot without selecting this (as we would do manually with the mouse).
    Thanks for any help
    Last edited by aca; 03-01-2012 at 05:03 PM.

  2. #2
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Macro line to move the cursor

    yup.

    Please Login or Register  to view this content.
    A mouse click in a cell is the same as a 'select' instruction.

  3. #3
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    Thanks, swoop99, for trying. But it's not so, unfortunately:

    My macro ends with a certain cell being selected (framed in bold); but the cursor itself (shaped as a cross) remains somewhere else.
    And if I just rightclick then, which in my project will run a second macro, its action will apply to the cell where the cursor remained, not to the cell selected by the last line of my first macro.

    Thanks for new tips.
    ACA

  4. #4
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    New precision, in case it helps:
    When my macro ends up with an instruction to select one particular cell, the cursor itself (shaped as a cross) remains positioned where I last typed manually or clicked manually (this other cell being unselected).
    ACA
    Last edited by aca; 02-29-2012 at 07:22 AM.

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro line to move the cursor

    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  6. #6
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    Thank you Dumsky. Sophisticated and useful tip.
    ACA

  7. #7
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Macro line to move the cursor

    Quote Originally Posted by aca View Post
    New precision, in case it helps:
    When my macro ends up with an instruction to select one particular cell, the cursor itself (shaped as a cross) remains positioned where I last typed manually or clicked manually (this other cell being unselected).
    ACA
    Can you post your workbook or an example of...?

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro line to move the cursor

    I guess the question should really be why you are trying to control the cursor. Other than for show there's never any real need to do so in the same way there is little or no need to select cells, sheets, charts etc when working with them in VBA.

    Dom

  9. #9
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    Thanks for your interest, Swoop99. By the way, the solution you suggested before, I cannot make it work: too advanced for me… Sorry.
    Thanks Domski as well; please, see below why I want to control the cursor.

    Now, Swoop99, my workbook is too long and messy to post, with several long macros etc. An example? Easy. It’s what happens also outside of a macro, when working directly on a worksheet:

    - Left-click on cell A1: this cell is selected and the mouse cursor is on A1 also.
    - Now type ENTER, say 3 times, (or the down arrow key); cell A4 is now selected.
    But the cursor pointer remains on A1; and if you just right-click now, the contextual menu that drops down refers to A1, not to A4 (for that clicking results on selecting A1 anew); of course you can go and right-click on A4, but first you have to travel with the mouse from A1 to A4 and then right-click.

    Well, what I want is for the cursor to follow on, and point to the cell newly selected by typing on the keyboard (in this case A4), so that, by just right-clicking (without first having to travel with my pointer to the new selected cell), the options of the drop down menu will act on this A4 cell, not on A1. But, that automatic travelling being part of a macro. Any clues?

    Much obliged.
    ACA
    Last edited by aca; 02-29-2012 at 07:03 PM.

  10. #10
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro line to move the cursor

    Seems a lot of bother to go to. Most keyboards have a key to the left of the right hand Ctrl key which brings up the same menu as right clicking and will relate to the selected cell and not the position of the cursor.

    Dom

  11. #11
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    True, Romski, my keyboard has got that key, and it works exactly as you say (thanks a lot). But…

    Actually, what I need is not to choose an action from that drop-down menu; it is to launch another macro that will perform several other functions.

    Presently I launch it by manually bringing the cursor on the selected cell and right-cliking on it, and with this Private Sub Worksheet code:

    Please Login or Register  to view this content.
    Can I call MyMacro by typing the key you mention? I don’t think so: that key does not register in Visual Basic. Still your contribution looks like a very promising step towards solving my problem. Any further such steps? Thanks in advance.
    ACA

  12. #12
    Registered User
    Join Date
    09-20-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Macro line to move the cursor

    Anything is possible but I've never heard of anyone wanting to programatically control a worksheet by being dependant on cursor position. Its a very odd and inefficient method. If you post more information about what you need to do I'm sure someone will offer a better way of doing it than by trying to move the cursor.

  13. #13
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro line to move the cursor

    You could add a custom menu item that is only available when that cell is selected:

    http://msdn.microsoft.com/en-us/library/gg469862.aspx

    Dom

  14. #14
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    Thanks, Domski. I see it, and you’re right. Only, I’m afraid that’s to advanced for me.

    Thank you also, Riggers. I’m sorry my query is so odd. But in case someone finds a better way, as you say, I explain again:

    - I last clicked on cell G9 and that click launched Macro1
    - That macro ended its last operation by selecting cell B2; but the mouse cursor remained on G9.
    - The next thing I need to do is right-click on B2 (to launch Macro2); for this, first I have to manually bring the mouse cursor from G9 to B2 and then right-click.
    - This moving of the mouse cursor is what I would like to have automatically done by some code at the end of Macro1 that would bring the mouse cursor from G9 to B2 that it has just selected.I didn’t imagine that wish could be so unheard of.

    Anyway, thanks for your efforts.
    ACA

  15. #15
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro line to move the cursor

    I think it's time to throw in the towel on this one or you'll spend an eternity for something that really doesn't seem worth the hassle.

    Dom

  16. #16
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    All right.
    Thanks again, Domski, for your effort and your savvy advice.
    ACA

  17. #17
    Registered User
    Join Date
    09-20-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Macro line to move the cursor

    Why do you have to launch macro2 by right clicking on cell B2? You can launch macro2 any number of ways and if it's dependant on B2 being the active cell it will still run ok regardless of cursor position. Can't you just insert some buttons at the top of the sheet to run each macro? If there is a lot of scrolling involved in the worksheet you could put the buttons in Row 1 then split and freeze the pane so row 1 is always visible.

  18. #18
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    Thanks, Rigger, for this.
    Yes, Macro2 is dependent on B2 being the active cell.
    But, as you say, there are other ways of launching Macro2; and in fact, silly me!, I already have the button you suggest (as part of a UserDefined box) that I use to lauch the same macro from other situations.

    Thanks for all your effort and sound advice.
    ACA

  19. #19
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro line to move the cursor

    hi aca,

    if your code 1 ends up in a different cell position from the cell the cursor is pointing on and you need to right-click to start code 2 and:

    - you do not need any other actions in between these codes, why not to combine them in one and omit your manual right-clicking?

    or

    - you do need to make some actions and cursor position does not change, the code 2 can be changed from event code to a standard one that will fire up on pressing set key combination and will work with the selected cell

  20. #20
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: Macro line to move the cursor

    Thanks, Watersev
    hi aca,

    "- you do not need any other actions in between these codes, why not to combine them in one and omit your manual right-clicking?"
    Answer: Yes, such is the case, but I cannot combine Macro1 and Macro2 because not always will I want to run Macro2, most of the times but now always, depending on results obtained from Macro1.

    or

    - you do need to make some actions and cursor position does not change, the code 2 can be changed from event code to a standard one that will fire up on pressing set key combination and will work with the selected cell.
    Answer: Yes, that is what I've decided to do (as advised by a previous forum helper), or something equivalent (having a button linked to Macro2).

    Thank you for helping too.
    (I'd like to tag this thread as SOLVED but I don't know how to go about it)
    ACA
    Last edited by aca; 03-01-2012 at 12:51 PM.

  21. #21
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro line to move the cursor

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1