Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Execute vba code on cell exit

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!

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Execute vba code on cell exit

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.

"Bill (Unique as my name)" wrote:

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!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Execute vba code on cell exit

Thanks, Dave. Worked like a jewel. Amazing. Simply amazing.

On May 23, 10:31 pm, Dave Peterson wrote:
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.

"Bill (Unique as my name)" wrote:



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!


--

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
how to execute a formula copied into an excel cell Das K Excel Worksheet Functions 1 December 13th 06 07:01 AM
macros doesn't execute unless i go into cell and press enter. Emma Excel Discussion (Misc queries) 2 October 20th 06 05:12 PM
can i execute a calculation in a cell at a certain time of the day terry Excel Worksheet Functions 2 June 9th 06 04:03 PM
how do you execute single line of code? honestlylion Excel Discussion (Misc queries) 2 February 24th 06 03:35 PM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM


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