Worksheet Change Event

D

DCSwearingen

I saw a forum response a while back that will allow programming the
cursor to move to certain cells as the user enters data.

I cannot remember how that was done.

Can someone refresh my memory?

This time I will copy the information into my own little help file.
 
D

Dave Peterson

The code may have used the worksheet_change event.

Here's a sample that moves the value entered in column A to column B:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub 'one cell at a time

If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub 'only look for changes in column A
End If

'stop the code from triggering the event
Application.EnableEvents = False
Me.Cells(Target.Row, "B").Value = Target.Value
Target.ClearContents
Application.EnableEvents = True

End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

You can read more about these kinds of events at:
Chip Pearson's site:
http://www.cpearson.com/excel/events.htm

David McRitchie's site:
http://www.mvps.org/dmcritchie/excel/event.htm
 
Top