+ Reply to Thread
Results 1 to 4 of 4

VBA code for cursor movement without leaving scroll area

  1. #1
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253

    VBA code for cursor movement without leaving scroll area

    I have the following code to run using the control + enter. It works great but when I add the vba code to move the cursor to the right, it goes beyond the scroll area range I have set up (instead of going to the next row & 1st cell in the scroll area).

    Anyone got any ideas how to move the cursor without it leaving the scroll area?

    In other words, when I hit the conrol + Enter, I want the data from the cell above to copy to the active cell & move the cursor to the next cell without having to hit enter again.

    Thanks,

    mikeburg


    [VBA]
    Sub WTurnOnCtrlEnter()
    'Turns on control + enter
    Application.OnKey "^~", "YDefaultMacro"
    End Sub
    Sub YDefaultMacro()
    ActiveCell.Offset(0, 0) = ActiveCell.Offset(-1, 0)
    End Sub
    Sub XTurnOffCtrlEnter()
    'Turns off control + enter
    Application.OnKey "^~"
    End Sub
    [\VBA]

  2. #2
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    Just add this line

    ActiveCell.Offset(1, 0).Select

    after your

    ActiveCell.Offset(0, 0) = ActiveCell.Offset(-1, 0)


    HTH

  3. #3
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253

    ActiveCell.Offset(0, 0) = ActiveCell.Offset(-1, 0) didn't work

    ActiveCell.Offset(0, 0) = ActiveCell.Offset(-1, 0) carries the cursor outside the set scroll area.

    Any other ideas?

  4. #4
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    What is your scroll area?

    The way I read you post is that you have the cursor in cell A2 and when you hit enter you want the value from cell A1 to be copied to A2 and then the cursor to move to A3.

    If that is the case this should work.

    Sub YDefaultMacro()
    ActiveCell.Offset(0, 0) = ActiveCell.Offset(-1, 0)
    ActiveCell.Offset(1, 0).Select
    End Sub

+ 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