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

Hi all, I have a spreadsheet where I have to fill in the following cells one
after the other if data is entered into cell C1: they a D1, E1 then C3, C4
and C5. These are the only cells needed to be input in that order, can anyone
help me with this.
Thanks all in anticipation of your appreciated help.


--
delmac
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default next cell

Hi,

Maybe you want something like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static OldTarget As Range
If OldTarget Is Nothing Then
Set OldTarget = Target
Else
Select Case OldTarget.Address
Case "$C$1"
Range("D1").Select
Case "$D$1"
Range("E1").Select
Case "$E$1"
Range("C3").Select
Case "$C$3"
Range("C4").Select
Case "$C$4"
Range("C5").Select
End Select
Set OldTarget = ActiveCell
End If
End Sub


Copy this into the code module for the sheet you are interested in.
Then, pressing enter when in cell C1 will get you to D1, pressing enter
in cell E1 will get you to C3 etc. If this isn't what you are looking
for then you need to be a little more clear in your question.

HTH

-John Coleman
delmac wrote:
Hi all, I have a spreadsheet where I have to fill in the following cells one
after the other if data is entered into cell C1: they a D1, E1 then C3, C4
and C5. These are the only cells needed to be input in that order, can anyone
help me with this.
Thanks all in anticipation of your appreciated help.


--
delmac


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

Random observation: my last 2 cases seem superfluous since passing from
c3 to c4 is the default behavior. A few points about my code which
might lead to some undesirable behavior:

1) It *forces* you to go through the sequence. So you can't, for
example, just change E1 and then go somewhere else - you have to go to
C3 next, etc. If you want this behavior - then forget about what I said
about the last 2 cases being superfluous. If you don't want this
behavior, then maybe some similar code with the worksheet change event
could work (though this would have troubles of its own - you don't
sequence unless you *change* the cells - just pressing enter to keep
the current value would no longer work).

2) You can pick up the sequence in mid-stride. Starting at E1 (without
previously being in C1) would take you to C3 next, etc. If this is a
problem for any reason, it would be easy enough to introduce a boolean
flag (something called, say, "started") which is set to true the first
time C1 is entered and is set back to false when C5 is left.

3) If you save the workbook while C1 is selected then the code doesn't
work next time it is opened. A manual work around is to first select
say A1 before moving back to C1. A more principled approach would be to
initialize OldTarget in the workbook open event - but I don't see much
point in going this rout for what would probably be a very infrequent
hassle in a macro that sounds like it's just designed to save a few
mouse moves.

HTH

-John Coleman

John Coleman wrote:
Hi,

Maybe you want something like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static OldTarget As Range
If OldTarget Is Nothing Then
Set OldTarget = Target
Else
Select Case OldTarget.Address
Case "$C$1"
Range("D1").Select
Case "$D$1"
Range("E1").Select
Case "$E$1"
Range("C3").Select
Case "$C$3"
Range("C4").Select
Case "$C$4"
Range("C5").Select
End Select
Set OldTarget = ActiveCell
End If
End Sub


Copy this into the code module for the sheet you are interested in.
Then, pressing enter when in cell C1 will get you to D1, pressing enter
in cell E1 will get you to C3 etc. If this isn't what you are looking
for then you need to be a little more clear in your question.

HTH

-John Coleman
delmac wrote:
Hi all, I have a spreadsheet where I have to fill in the following cells one
after the other if data is entered into cell C1: they a D1, E1 then C3, C4
and C5. These are the only cells needed to be input in that order, can anyone
help me with this.
Thanks all in anticipation of your appreciated help.


--
delmac


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
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Options Yuvraj Excel Discussion (Misc queries) 0 June 29th 09 11:20 AM
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Yuvraj Excel Discussion (Misc queries) 0 June 26th 09 06:01 PM
Populate a cell if values in cell 1 and cell 2 match cell 3 and 4 [email protected] Excel Worksheet Functions 1 August 22nd 08 02:04 AM
How to create/run "cell A equals Cell B put Cell C info in Cell D abmb161 Excel Discussion (Misc queries) 5 January 26th 06 06:36 PM
data validation to restrict input in cell based on value of cell above that cell NC Excel Programming 2 January 25th 05 07:11 AM


All times are GMT +1. The time now is 08:22 AM.

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"