PC Review


Reply
Thread Tools Rate Thread

Cells: Any way to code an event behind one?

 
 
(PeteCresswell)
Guest
Posts: n/a
 
      9th Dec 2006
I'm thinking I'd like to automatically select the next cell in a series after
the user pastes something into the current cell.

Can I write event code for a given cell, like "Cell(2,3).AfterUpdate()"?
--
PeteCresswell
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      9th Dec 2006
It should be easy with a change event, but what does ... next cell in a
series ... mean?

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"(PeteCresswell)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm thinking I'd like to automatically select the next cell in a series
> after
> the user pastes something into the current cell.
>
> Can I write event code for a given cell, like "Cell(2,3).AfterUpdate()"?
> --
> PeteCresswell



 
Reply With Quote
 
(PeteCresswell)
Guest
Posts: n/a
 
      9th Dec 2006
Per Bob Phillips:
>It should be easy with a change event, but what does ... next cell in a
>series ... mean?


If I'm in R1C3, I'd want to move focus to R2C3.

How would the macro be named?

Or can it be any name and somehow associated with the cell via the UI?
--
PeteCresswell
 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      10th Dec 2006
Pete,

You need to use the Change event code. Right-click the appropriate sheet tab
and choose View Code. This will take you to that sheet's object module in
the VBA editor. Paste in the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
'''''''''''''''''''''''''''''
' Restrict actions to A1:A10)
'''''''''''''''''''''''''''''
Dim ISect As Range
Set ISect = Application.Intersect(Me.Range("A1:A10"), Target)
If ISect Is Nothing Then
Exit Sub
Else
If ISect.Cells.Count <> Target.Cells.Count Then
Exit Sub
End If
End If
Application.EnableEvents = False
Target.Cells(Target.Cells.Count)(2, 1).Select
Application.EnableEvents = True

End Sub

This code will select the cell below the paste operation after the paste. As
written, it will apply only to changes in the range A1:A10. Change that
range reference as appropriate.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"(PeteCresswell)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Per Bob Phillips:
>>It should be easy with a change event, but what does ... next cell in a
>>series ... mean?

>
> If I'm in R1C3, I'd want to move focus to R2C3.
>
> How would the macro be named?
>
> Or can it be any name and somehow associated with the cell via the UI?
> --
> PeteCresswell



 
Reply With Quote
 
(PeteCresswell)
Guest
Posts: n/a
 
      10th Dec 2006
Per Chip Pearson:
>You need to use the Change event code. Right-click the appropriate sheet tab
>and choose View Code. This will take you to that sheet's object module in
>the VBA editor. Paste in the following code:
>
>Private Sub Worksheet_Change(ByVal Target As Range)
> '''''''''''''''''''''''''''''


Thanks Chip.

The big revelation to Yours Truly was the concept of Worksheet_Change().
--
PeteCresswell
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event's code runs to completion before another event's code is entered? Academia Microsoft VB .NET 8 1st Nov 2007 07:13 PM
creating event handler in unmanaged c++ code for event in managed code Mayur Microsoft C# .NET 0 30th Aug 2006 02:01 PM
creating event handler in unmanaged c++ code for event in managed code Mayur Microsoft VC .NET 0 30th Aug 2006 01:22 PM
How to make double click event to call and execute the mouseup event code techsatish@gmail.com Microsoft Dot NET Framework Forms 0 25th Aug 2006 04:26 AM
Can I stop code in a Worksheet_Change event with a Worbook_Deactivate event code? Ronaldo Microsoft Excel Programming 0 17th Nov 2004 05:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:01 AM.