#1   Report Post  
Posted to microsoft.public.excel.misc
Alec H
 
Posts: n/a
Default Moving between cells


Hi,

I have constructed a sheet that the user has to input data into and
then upon completion press an on sheet command button to confirm.

My problem is simple (I hope), I want to be able to dictate which cell
the curser will move to upo completion of each entry.

My example is;

Cell B2 - Input
then
Cell C7 - Input
then
Cell B6 - Input
then
Command Button

Is there an easy way of doing this without forcing the user to use the
mouse to select the cells they need in the right order?




--
Alec H
------------------------------------------------------------------------
Alec H's Profile: http://www.excelforum.com/member.php...o&userid=31042
View this thread: http://www.excelforum.com/showthread...hreadid=522094

  #2   Report Post  
Posted to microsoft.public.excel.misc
nsv
 
Posts: n/a
Default Moving between cells


Look at this example which works with the DOWN-ARROW, which I find more
simple than pushing a botton. It starts out at G11 and after filling
out G11 you push the DOWN-ARROW. This makes the cursor jump to A14,
etc.


Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'macro
jump cell

If Target.Row = 12 And Target.Column = 7 Then 'jump A14
Target.Offset(2, -6).Select
End If

If Target.Row = 15 And Target.Column = 1 Then 'jump B14
Target.Offset(-1, 1).Select
End If

End Sub


--
nsv
------------------------------------------------------------------------
nsv's Profile: http://www.excelforum.com/member.php...o&userid=26500
View this thread: http://www.excelforum.com/showthread...hreadid=522094

  #3   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default Moving between cells

You should disable events in this procedure, and turn them back
on at the end.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'macro jump cell
Application.EnableEvents = False '<<<<<<<<<<<
If Target.Row = 12 And Target.Column = 7 Then 'jump A14
Target.Offset(2, -6).Select
End If

If Target.Row = 15 And Target.Column = 1 Then 'jump B14
Target.Offset(-1, 1).Select
End If
Application.EnableEvents = True '<<<<<<<<<<<
End Sub

Otherwise, you'll find that the macro is calling itself. The
SelectionChange code changes the Selection, which calls
SelectionChange again.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"nsv" wrote in
message ...

Look at this example which works with the DOWN-ARROW, which I
find more
simple than pushing a botton. It starts out at G11 and after
filling
out G11 you push the DOWN-ARROW. This makes the cursor jump to
A14,
etc.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'macro
jump cell

If Target.Row = 12 And Target.Column = 7 Then 'jump A14
Target.Offset(2, -6).Select
End If

If Target.Row = 15 And Target.Column = 1 Then 'jump B14
Target.Offset(-1, 1).Select
End If

End Sub


--
nsv
------------------------------------------------------------------------
nsv's Profile:
http://www.excelforum.com/member.php...o&userid=26500
View this thread:
http://www.excelforum.com/showthread...hreadid=522094



  #4   Report Post  
Posted to microsoft.public.excel.misc
Alec H
 
Posts: n/a
Default Moving between cells


Thank You

:)


--
Alec H
------------------------------------------------------------------------
Alec H's Profile: http://www.excelforum.com/member.php...o&userid=31042
View this thread: http://www.excelforum.com/showthread...hreadid=522094

  #5   Report Post  
Posted to microsoft.public.excel.misc
nsv
 
Posts: n/a
Default Moving between cells


...but Chip, until now I have run my spreadsheet without the disabling
of events and it works perfectly. It is only a small one, actually just
a form to be filled out in certain cells only and there are almost no
calculations.

I will of course put in the extra lines you recommend, but what can go
wrong if I do not disable events?

NSV


--
nsv
------------------------------------------------------------------------
nsv's Profile: http://www.excelforum.com/member.php...o&userid=26500
View this thread: http://www.excelforum.com/showthread...hreadid=522094



  #6   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Moving between cells

I'm not Chip, but If you put a break point in your code (right near the top),
then stepped through the code after the break, you'd see what was really
happening. Not quite what you expect. But with the speed of the pc (and the
code you're running), you don't notice the difference.

You can also see it by adding a single msgbox:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'macro jump cell

MsgBox "hi from worksheet change!"

If Target.Row = 12 And Target.Column = 7 Then 'jump A14
Target.Offset(2, -6).Select
End If

If Target.Row = 15 And Target.Column = 1 Then 'jump B14
Target.Offset(-1, 1).Select
End If

End Sub

And depending on what your code does, lots can go wrong or nothing can go, er,
look wrong.

Here's a worksheet_change event that looks like it would just add something to
the cell below the changed cell:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Target.Offset(1, 0) = "hi"
End Sub

But changing that cell below causes the event to fire, which causes the cell
below to change which causes the event to fire......until excel gets tired (it
does try to protect itself a little bit).

I changed A1 and excel got tired when it changed A227 (xl2003).

nsv wrote:

..but Chip, until now I have run my spreadsheet without the disabling
of events and it works perfectly. It is only a small one, actually just
a form to be filled out in certain cells only and there are almost no
calculations.

I will of course put in the extra lines you recommend, but what can go
wrong if I do not disable events?

NSV

--
nsv
------------------------------------------------------------------------
nsv's Profile: http://www.excelforum.com/member.php...o&userid=26500
View this thread: http://www.excelforum.com/showthread...hreadid=522094


--

Dave Peterson
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
Copy/Paste how to avoid the copy of formula cells w/o calc values Dennis Excel Discussion (Misc queries) 10 March 2nd 06 10:47 PM
30 Day Moving Average Ignoring Blank Cells ethatch Excel Worksheet Functions 2 January 17th 06 09:37 AM
moving cells based certain value Rose Davis New Users to Excel 1 August 29th 05 09:53 PM
Heps to design Locked/Unlocked cells in protected worksheet Kevin Excel Discussion (Misc queries) 0 December 30th 04 07:09 AM
Convert data of cells to any type: Number, Date&Time, Text Kevin Excel Discussion (Misc queries) 0 December 30th 04 06:55 AM


All times are GMT +1. The time now is 09:57 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"