Consulting

Results 1 to 5 of 5

Thread: Go back to cell

  1. #1

    Cool Go back to cell

    On my excel sheet when i click on a cell it changes color of another cell. but I need it to go back to the cell that I click so I can type some information in there. How can I do these? (using like a varable thing)

    Here is what I got for now.


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("C7:Z7")) Is Nothing Then
    GOBLACK
    Range("a7").Select
    Selection.Font.ColorIndex = 3
    End If
    End Sub
     
    Private Sub GOBLACK()
    Range("A7:A150").Select
    Selection.Font.ColorIndex = 1
    Range("A1").Select
    End Sub
    thanks for the help.

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi there!

    You don't really need to do that Selecting if you don't want to. When using the worksheet change/select events, you can see you automatically have some variables setup for you between the parenthases of your routine header line. In this case .. [vba](ByVal Target As Range)[/vba] is saying that Target is the range object in which the reference is made to the routine/event. So if you select a cell, Target is the cell which you selected. All you'd need to do to stay in the same cell is .. [vba]Target.Select[/vba] Although you shouldn't really need to do this.

    Is this what you are talking about?

  3. #3
    thanks

  4. #4
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    Quote Originally Posted by firefytr
    Hi there!

    You don't really need to do that Selecting if you don't want to. When using the worksheet change/select events, you can see you automatically have some variables setup for you between the parenthases of your routine header line. In this case ..
    (ByVal Target As Range)
    is saying that Target is the range object in which the reference is made to the routine/event. So if you select a cell, Target is the cell which you selected. All you'd need to do to stay in the same cell is ..
    Target.Select
    Although you shouldn't really need to do this.

    Is this what you are talking about?
    Very Good...firefytr! Learn new code today..

    blackice, Welcome to VBA Express!
    Hope you enjoy the forum

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Glad it helped.

    Just as a side note, I use Select instead of Activate, as the user may have selected more than one cell .. and you can't Activate more than one cell at a time.

Posting Permissions

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