code enter key action to shift to right on one excel sheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buddyr
    New Member
    • Apr 2007
    • 105

    code enter key action to shift to right on one excel sheet

    can I use VB to work in microsoft excel to cause the enter button to shift to the right instead of down. I only want one worksheet to have this in.
    Trying to get code in Private Sub Worksheet_chang e(ByValTarget as range) procedure.
    No matter what I do - I cause all my excel sheets to go to the right when I hit enter and I only want one worksheet to.
    any ideas
    thank you
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by buddyr
    can I use VB to work in microsoft excel to cause the enter button to shift to the right instead of down. I only want one worksheet to have this in.
    Trying to get code in Private Sub Worksheet_chang e(ByValTarget as range) procedure.
    No matter what I do - I cause all my excel sheets to go to the right when I hit enter and I only want one worksheet to.
    any ideas
    thank you
    only write it inside a single sheet's code, not inside the workbook's or a module's code.

    this might help:

    [CODE=vb]Sub Worksheet_chang e(ByVal Target as range)

    target.offset(0 ,1).select

    end sub[/CODE]

    or

    [CODE=vb]dim Boo1 as boolean
    Sub Worksheet_selec tionchange(ByVa l Target as range)
    if boo1= false then
    boo1=true
    if target.row > 1 then target.offset(-1,1).select
    boo1=false
    end if
    end sub[/CODE]



    for something more complex, you might need to define the GetAsyncKeyStat e function.

    HTH

    Comment

    • buddyr
      New Member
      • Apr 2007
      • 105

      #3
      Thanks for solutions- sorry took long to get back-
      first solution:
      If I input a number and hit enter- it goes to the right.
      but if I don't input a number it does nothing. and if I am in cell with number I do not change it does not move either.

      second solution:
      it moves to the right but I can't even select a cell other than in the first row

      any more ideas
      Thank you

      Comment

      • kadghar
        Recognized Expert Top Contributor
        • Apr 2007
        • 1302

        #4
        Originally posted by buddyr
        Thanks for solutions- sorry took long to get back-
        first solution:
        If I input a number and hit enter- it goes to the right.
        but if I don't input a number it does nothing. and if I am in cell with number I do not change it does not move either.

        second solution:
        it moves to the right but I can't even select a cell other than in the first row

        any more ideas
        Thank you
        Well, if the second solution does that, its because you didnt define the boolean called Boo1 outside the sub, as a declaration. Or maybe you defined it in someother module, but not as a public variable.

        The problem that solution has, is that no matter what, when you select a cell, you'll be selecting the one above and right from it. That's why i put the second suggestion.

        With GetAsyncKeyStat e you can check if the key used to change the selection was the [enter] key, and in that case, run the code.

        Comment

        Working...