+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Contributor
    Join Date
    07-16-2009
    Location
    Bucharest, Romania
    MS-Off Ver
    MS Office 2007
    Posts
    157

    Adjust direction for "Enter"

    Hello everyone,

    I have this macro that automatically inserts the date in column B when data is entered in column D. What I would like to is when I press enter in a cell in column D then the selection cell will move to column E and then when I enter again in column E then move to column D again on the next row.
    IE. if I'm in D12 and press enter then move to E12 and then move to D13 and so on.

    Thanks for all your help,
    Alex

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Then Exit Sub
    
            If Not Intersect(Target, Range("D5:D400")) Is Nothing Then
    
                With Target(1, -1)
    
                    .Value = Now
    
                    .EntireColumn.AutoFit
    
                End With
    
            End If
    
    End Sub
    Last edited by Alexander Ceed; 01-28-2010 at 06:54 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,493

    Re: Adjust direction for "Enter"

    Hello Alex,

    The easiest way is to protect the worksheet and unlock the cells that will be used for entering the data.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    07-16-2009
    Location
    Bucharest, Romania
    MS-Off Ver
    MS Office 2007
    Posts
    157

    Re: Adjust direction for "Enter"

    Thanks for the suggestion. I did as you said Ross and now it just goes through the cells that are unlocked but the problem is that I need to keep the column B unlocked for the vba to work and I don't want to be able to select any cell in that column.

  4. #4
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: Adjust direction for "Enter"

    How about adding

    Code:
    Application.MoveAfterReturnDirection = xlToRight
    somewhere at the beginning of the code and then changing it back to

    Code:
    Application.MoveAfterReturnDirection = xlDown
    before the workbook is closed.

    With regards to this:
    the problem is that I need to keep the column B unlocked for the vba to work
    You can use something like

    Code:
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
    to protect the sheet from user input but still enable VBA access to locked cells. Then Leith's suggestion might be the easiest way to go.
    Last edited by teylyn; 01-28-2010 at 06:29 AM.
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  5. #5
    Forum Contributor
    Join Date
    07-16-2009
    Location
    Bucharest, Romania
    MS-Off Ver
    MS Office 2007
    Posts
    157

    Re: Adjust direction for "Enter"

    Thanks Teylyn and you too Ross. This is all that I needed and it works like a charm now.
    Code:
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
    It wasn't about protecting the cells but I needed a way to jump only in the cells that needed editing. Saves time as well. Thanks again you guys and I'll add some points to your reputation status.

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.2.0