Consulting

Results 1 to 3 of 3

Thread: If statement if cell is active?

  1. #1

    If statement if cell is active?

    Hi everybody.

    This is a simple problem but i could not find an answer through google!
    Im running a code, using byval:

    Private Sub worksheet_change(ByVal target As Range)
    If Not Application.Intersect(Range("H9:I9"), Range(target.Address)) Is Nothing Then
    Call Special
    End If
    End Sub

    Within the sub "Special" i want only one of the cells (I9) to switch "back" if you press enter... I had hoped that the following was possible:


    If ActiveCell = ActiveSheet.Range("I10") Then
    ActiveCell.Offset(-1, 0).Select
    End If

    I.e. if you push enter in the field I9 and it goes to I10, then it should go back to I9. In H9 i have used a list (from data validation) so it's not a problem! Does anybody know how i can create an if statement, which does an action, if the cell "I10" is activated?

    Cheers!

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    If I don't want them in a cell, I would just lock it and protect the sheet.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)  
      If Intersect(Target, [I10]) Is Nothing Then Exit Sub
      With Application
        .EnableEvents = False
        Target.Offset(, -1).Select
        .EnableEvents = True
      End With
    End Sub

  3. #3
    Quote Originally Posted by Kenneth Hobs View Post
    If I don't want them in a cell, I would just lock it and protect the sheet.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)  
      If Intersect(Target, [I10]) Is Nothing Then Exit Sub
      With Application
        .EnableEvents = False
        Target.Offset(, -1).Select
        .EnableEvents = True
      End With
    End Sub

    Ah nice! Thank you very much Kenneth!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •