#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default GoTo cell..

Hi, I have a Private Sub Worksheet_Change(ByVal target As Range) macro which
does something when value changes in a particular cell..

But when user input any value they may press right arrow or down arrow..

Is there a way to go back to cell in which value was entered recently? as I
need to perform some tasks over there..
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default GoTo cell..

Here is an example of detecting a change in B9, doing something, and then
returning to B9:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("B9")
If Intersect(r, Target) Is Nothing Then Exit Sub
MsgBox ("back we go!")
r.Select
End Sub

--
Gary''s Student - gsnu200850


"Kashyap" wrote:

Hi, I have a Private Sub Worksheet_Change(ByVal target As Range) macro which
does something when value changes in a particular cell..

But when user input any value they may press right arrow or down arrow..

Is there a way to go back to cell in which value was entered recently? as I
need to perform some tasks over there..

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default GoTo cell..

Do you mean go back to the cell just changed? If so:

Private Sub Worksheet_Change(ByVal Target As Range)

'go back if value = 3
If Target.Value = 3 Then
Range(Target.Address).Activate
End If

End Sub


Note that the above code refers to Range(Target.address). You can make
changes or go to other cells using this.

Example 1, go two cells to the right of target :

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Value = 3 Then
Range(Target.Address).Offset(, 2).Activate
End If

End Sub

Example 2, multiply the value by 2:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Value = 3 Then
'stay in the new address
'change the old value
Range(Target.Address).value = Range(Target.Address)*2
End If

End Sub

Almost forget to mention:

You need to wrap your code in an if condition to ensure it doesn't activate
when a range of cells are deleted or updated at the same time (paste, drag &
drop, etc)

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Target.Value = 3 Then
Range(Target.Address).Value = Range(Target.Address) * 2
End If
End If

End Sub



--
Steve

"Kashyap" wrote in message
...
Hi, I have a Private Sub Worksheet_Change(ByVal target As Range) macro
which
does something when value changes in a particular cell..

But when user input any value they may press right arrow or down arrow..

Is there a way to go back to cell in which value was entered recently? as
I
need to perform some tasks over there..


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
goto last cell with data W[_2_] Excel Programming 3 October 21st 08 05:38 PM
Goto last cell Martin B Excel Programming 1 February 15th 08 09:52 PM
How to goto the next available cell in a column. [email protected] Excel Programming 1 October 26th 06 05:15 PM
Goto Next VISIBLE cell below Rasmus[_2_] Excel Programming 5 May 24th 04 04:26 AM
goto a particular cell Newbie Excel Programming 5 April 15th 04 01:46 PM


All times are GMT +1. The time now is 03:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"