PDA

View Full Version : [SOLVED:] Go back to cell



blackice
07-06-2005, 08:38 AM
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.:bow:

Zack Barresse
07-06-2005, 08:48 AM
Hi there! :hi:

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?

blackice
07-06-2005, 09:38 AM
thanks

sheeeng
07-06-2005, 07:18 PM
Hi there! :hi:

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! :thumb Learn new code today..:friends:

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

Zack Barresse
07-07-2005, 08:12 AM
Glad it helped. :yes

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. ;)