+ Reply to Thread
Results 1 to 9 of 9

Record ActiveCell Location prior to cell movement

  1. #1
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Record ActiveCell Location prior to cell movement

    I'm having a problem with the beforeDoubleClick routine below:

    Please Login or Register  to view this content.
    I want it to record where the cursor is and place the range name "rms" in that location. Then it should evaluate the double-click location and take the indicated action - works fine by the way. Then the cursor should return to the "rms" location and delete that range name.

    The "rms" range name is always attached to the cell that is double-clicked. I was under the impression that this type of code would fire prior to any double-click action.

    Can any offer any suggestions as to where I went wrong?

    TIA.

    Bob
    Last edited by bstubbs; 03-19-2009 at 07:22 AM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,520

    Re: Record ActiveCell Location prior to cell movement

    Hi Bob,

    Try adding the following statement as the last line of your code:
    Please Login or Register  to view this content.
    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Record ActiveCell Location prior to cell movement

    Your macros that are called must move the cell. What do these macros do? It is generally unnecessary to slect or activate ranges in VBA so the activecell could remain the same.

    Try attaching the workbook so that we can see what you are dong.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Re: Record ActiveCell Location prior to cell movement

    GregM:

    Nope that didn't do it. It's still like the entire routine is being executed after the double-click not before it.

    Thanks

    Bob

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,520

    Re: Record ActiveCell Location prior to cell movement

    Hi Bob,

    I used dummy "SelectSchool" and "SelectRoute" subroutines when testing your code. With these routines in place your code worked when I included the "Cancel = True" command, but would not work without it. When I say your code "worked", I mean that it successfully named the active cell as "rms" while the code was running, and that this name had been deleted when code execution was finished.

    In view of this, it seems that the main problem may lie within one or both of the subroutines - you could easily test this by temporarily including an "Exit Sub" command as the first line of code in each of the subroutines. If that locates the problem you could post the subroutines here so that we can take a look at them.

    Regards,

    Greg M

  6. #6
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Re: Record ActiveCell Location prior to cell movement

    GregM:

    Thank you, sir:

    The question that I have is what is the relationship of the "rms" label - is it in the activeCell before you double-clicked elsewhere or in the cell that you double-clicked. The routine has always done the later and I want it to do the former (the "rms" should mark the cell that was active prior to the double-click). Where is your proto-typed code putting the "rms" label?

    TIA.

    Bob

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,520

    Re: Record ActiveCell Location prior to cell movement

    Hi Bob,

    Ok - now I see what you're trying to do!

    E.g. the active cell is A1, you doubleclick on cell E5, and you want to return to cell A1 when your code has executed. The main problem is that the first click of the doubleclick selects cell E5 which immediately becomes the active cell. In effect, you're trying to trap a "BeforeCLICK" (not "BeforeDoubleClick") event.

    Unfortunately, as far as I know, Excel does not have a worksheet "BeforeClick" event, so it will be necessary to develop a workaround. The approach I used was to continuously track the previously selected cell - e.g. with cell A1 as the current selection, click on cell E5 and cell A1 is stored as the previously selected cell. Now click on cell B3, and E5 is stored as the previously selected cell, and so on.

    The following is the code I used in the VBA code module for the worksheet:
    Please Login or Register  to view this content.
    Plus the following code in a standard VBA code module:
    Please Login or Register  to view this content.
    This allowed me to select any cell (e.g. AP1) on the worksheet, doubleclick on any cell in the ranges you specify (AT2:AT24 etc.), have the BeforeDoubleClick code execute, and return automatically to cell AP1. Using this approach meant that I didn't need the user-defined name "rms".

    I hope the above helps - please let me know how you get on.

    Regards,

    Greg M

  8. #8
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Re: Record ActiveCell Location prior to cell movement

    Sir:

    You are a steely-eyed Excel-man! (apologies to Apollo-13).

    Thanks.

    Bob

  9. #9
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,520

    Re: Record ActiveCell Location prior to cell movement

    Hi again Bob,

    Many thanks for your feedback and for the compliment - I'm very pleased that I was able to help.

    Best regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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