Execute vba code on cell exit

  • Thread starter Thread starter Bill (Unique as my name)
  • Start date Start date
B

Bill (Unique as my name)

I came up with this much, but it does nothing. Help me please?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static Oldselection As Range
If Oldselection = "Meter Reading" Then
SendKeys "{RIGHT 2}Bill Coyne{RIGHT}FM", True
End If
End Sub

I want to fill in "Bill Coyne" two cells to the right and "FM" three
cells to the right if the cell I exit equals "Meter Reading"

Thank you!
 
You mean when you type "meter reading", you want to see Bill Coyne in one cell
and FM in another?

If yes, then maybe use the worksheet_change event instead of the
_selectionchange event.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Cells.Count > 1 Then Exit Sub
If Intersect(.Cells, Me.Range("A:A")) Is Nothing Then
Exit Sub
End If

On Error GoTo ErrHandler:

If LCase(.Value) = LCase("Meter Reading") Then
Application.EnableEvents = False
.Offset(0, 2).Value = "Bill Coyne"
.Offset(0, 3).Value = "FM"
End If
End With

ErrHandler:
Application.EnableEvents = True

End Sub

I checked for a change to column A. Change that to what you need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top