Results 1 to 11 of 11

Change behaviour of ENTER in selection with VBA

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-02-2012
    Location
    Mosselbaai, Suid Afrika
    MS-Off Ver
    Excel 2016
    Posts
    107

    Change behaviour of ENTER in selection with VBA

    I have a Worksheet_SelectionChange event that selects the row to the left of and including the active cell, as well as the column above and including the active cell, with the active cell remaining the original cell.

    Problem: When I type something in the active cell and Enter, instead of moving one cell down (which is what is required) it jumps to the start of the selection, as per normal. How can I programmatically change this behaviour so that the cell immediately below the active cell (i.e. the corner of the selection) becomes the new active cell?

    Option Explicit
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim lngRows As Long, lngCols As Long
    Dim CornerCell As Range
    lngRows = Selection.Rows.Count
    lngCols = Selection.Columns.Count
    
    If lngRows > 1 Or lngCols > 1 Then Exit Sub
    
    Set CornerCell = ActiveCell
    Application.EnableEvents = False
    
    Union(Range(Cells(CornerCell.Row, 1), Cells(CornerCell.Row, CornerCell.Column)), _
    Range(Cells(1, CornerCell.Column), Cells(CornerCell.Row, CornerCell.Column))).Select
    CornerCell.Activate
    Application.EnableEvents = True
    End Sub
    Regards,
    Henk Stander
    Last edited by Henk Stander; 12-19-2014 at 07:47 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. 'Tab' 'Enter' does not change cell selection
    By kheli in forum Excel General
    Replies: 0
    Last Post: 08-31-2011, 04:22 PM
  2. Centre across selection - strange behaviour when wrapping.
    By talksalot81 in forum Excel General
    Replies: 0
    Last Post: 04-27-2010, 12:34 PM
  3. How to change the behaviour of the "Enter" key
    By calvinbaisley in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2009, 07:24 PM
  4. [SOLVED] simulate a enter key behaviour?
    By Liedson31 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2005, 10:05 AM
  5. how to change (override) enter key behaviour in a cell
    By helpwithXL in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2005, 02:06 PM

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