ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Execute vba code on cell exit (https://www.excelbanter.com/excel-programming/390040-execute-vba-code-cell-exit.html)

Bill (Unique as my name)

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!


JE McGimpsey

Execute vba code on cell exit
 
One way:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Static rOldSelection As Range
If Not rOldSelection Is Nothing Then _
If rOldSelection.Text = "Meter Reading" Then _
rOldSelection.Offset(0, 2).Resize(1, 2).Value = _
Array("Bill Coyne", "FM")
Set rOldSelection = Target
End Sub


In article . com,
"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

Execute vba code on cell exit
 
See another suggestion at your other post.

"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


All times are GMT +1. The time now is 01:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com