+ Reply to Thread
Results 1 to 5 of 5

Enter key moves active cell unexpectedly after running code

  1. #1
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Red face Enter key moves active cell unexpectedly after running code

    G'day.
    Running Excel 2003 and XP Pro

    INTRO:
    This problem comes out of a larger chunk of code, in which I want users to be able to move only to cells where they need to make changes to cell values, and not to cells where they do not need to enter values. I'm trying to make it so that pressing the Enter key (when there is no change to make in a cell) will result in simply moving down one row (I would prefer to be able to make it go to a specific cell if there's no change, but I can't see any way of doing that... any ideas?). I have locked the non-use cells for change, but I need them to be selectable, so that the relevant part of the worksheet can be copied and pasted into a Word document.

    THE ISSUE:
    After running a macro (see below) in Excel, pressing the Enter key moves the active cell down one row and over to the column under the Target cell if two cells (or more) immediately under the target cell are merged. If they are not merged, the active cell simply moves down one row (in the same column) on Enter, as would be expected.

    The code below checks for a change in cell A1, and if TRUE, moves the active cell to G8. Pressing the Enter key then moves the active cell to G9, but if cells A2 and B2 are merged, the active cell moves to A9 on pressing Enter. I don't want this!

    Note: The same thing happens anywhere on a worksheet - not just at A1.

    TEST:
    To test this, cells A2 and B2 need to be merged. Then run the code by changing the value in A1 (active cell moves to G8). Then press Enter. On my PC, the active cell will now move to A9, instead of to G9.
    Unmerge A2 and B2, redo the steps, and the active cell will then move to G9, as expected.

    I've tried this on several PC's with the same result, but all use the same copy of Office 2003.

    Please Login or Register  to view this content.
    Thanks in advance for any help.
    Last edited by GCW esq; 11-25-2011 at 10:24 PM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Enter key moves active cell unexpectedly after running code

    Hey GCW esq

    you need to get rid of merged cells in your design layout as they only cause problems
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Re: Enter key moves active cell unexpectedly after running code

    Thanks Pike. I see what you mean. Unfortunately, it's a bit hard to get rid of merged cells (there's a presentation element to this).
    A couple of workarounds I tried were to put a dummy row under the target cell and hide the row (didn't work), or reduce the row height to zero (it worked down to a row height of 1 pixel, but not zero).
    I thought if I could reassign the target cell to somewhere else, it might solve the problem, but I haven't managed to find a way to do that.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Enter key moves active cell unexpectedly after running code

    can you attach the work sheet in a workbook?

  5. #5
    Registered User
    Join Date
    11-25-2011
    Location
    Lilydale, Victoria, Australia
    MS-Off Ver
    2013 (365)
    Posts
    63

    Re: Enter key moves active cell unexpectedly after running code

    Do you mean attach it to the Word document, or attach it to this thread?
    I have managed a rather inelegant workaround - I have put a blank, unmerged row above and below the problem cell, and reduced their heights to 1 pixel, then shifted the border onto those cells, then reduced the height of the problem row by 2 pixels.
    Is there no better way?

+ 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