ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   selection_change adding text to target (https://www.excelbanter.com/excel-programming/414937-selection_change-adding-text-target.html)

Matt Williamson

selection_change adding text to target
 
Can I use selection_change to modify the current cell?

e.g I want to type 1234 into any cell in column A and have it change to
"Test - 1234 - Test" upon leaving the cell

TIA

Matt



Bernie Deitrick

selection_change adding text to target
 
Matt,

Copy the code below, right-click the sheet tab, select "View Code" and paste the code into the
window that appears.

I've use the change event because you talk about typing in and not just selecting as cell

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
Application.EnableEvents = False
Target.Value = "Test - " & Target.Value & " - Test"
Application.EnableEvents = True
End Sub


"Matt Williamson" wrote in message
...
Can I use selection_change to modify the current cell?

e.g I want to type 1234 into any cell in column A and have it change to "Test - 1234 - Test" upon
leaving the cell

TIA

Matt





All times are GMT +1. The time now is 05:25 PM.

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