ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Cell value prefix (https://www.excelbanter.com/excel-worksheet-functions/10994-cell-value-prefix.html)

NDB

Cell value prefix
 
Hi,

I'm looking for a way to implement this ...

When a user selects cell A1 and enters a value (text), I would like the
displayed text to display a prefix also.

How can this be achieved?

eg. If user types in cell A1 the text value "Paul", when the enter key is
pressed, I would like the cell value displayed to be "England - Paul".
Likewise for example typing in "David" would give "England - David".

Cand this be done in using VBA or cell formatting?

TIA.

--
NDB.

(Remove [nospam] from e-mail address when corresponding by e-mail)




Tom Ogilvy

For VBA (you posted this in programming)
? ActiveCell.NumberFormat
"England - "@

- Manually
From the Menu
Format, cells, Number format Tab, choose custom

"England - "@




--
Regards
Tom Ogilvy


"NDB" wrote in message
...
Hi,

I'm looking for a way to implement this ...

When a user selects cell A1 and enters a value (text), I would like the
displayed text to display a prefix also.

How can this be achieved?

eg. If user types in cell A1 the text value "Paul", when the enter key is
pressed, I would like the cell value displayed to be "England - Paul".
Likewise for example typing in "David" would give "England - David".

Cand this be done in using VBA or cell formatting?

TIA.

--
NDB.

(Remove [nospam] from e-mail address when corresponding by e-mail)






Bernie Deitrick

NDB,

You could use the custom format of

;;;"England - "@

But that would only affect how the value is displayed. But you could use an
event to change the actual value - this example (below) will work on column
A. Copy the code, right click on the cell tab and select "View Code" then
paste in the window that appears:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Application.EnableEvents = False
If Left(Target.Value, 10) < "England - " Then
Target.Value = "England - " & Target.Value
End If
Application.EnableEvents = True
End If
End Sub

HTH,
Bernie
MS Excel MVP


"NDB" wrote in message
...
Hi,

I'm looking for a way to implement this ...

When a user selects cell A1 and enters a value (text), I would like the
displayed text to display a prefix also.

How can this be achieved?

eg. If user types in cell A1 the text value "Paul", when the enter key is
pressed, I would like the cell value displayed to be "England - Paul".
Likewise for example typing in "David" would give "England - David".

Cand this be done in using VBA or cell formatting?

TIA.

--
NDB.

(Remove [nospam] from e-mail address when corresponding by e-mail)






NDB

"Tom Ogilvy" wrote in message
...
For VBA (you posted this in programming)
? ActiveCell.NumberFormat
"England - "@

- Manually
From the Menu
Format, cells, Number format Tab, choose custom

"England - "@




--
Regards
Tom Ogilvy


"NDB" wrote in message
...
Hi,

I'm looking for a way to implement this ...

When a user selects cell A1 and enters a value (text), I would like the
displayed text to display a prefix also.

How can this be achieved?

eg. If user types in cell A1 the text value "Paul", when the enter key

is
pressed, I would like the cell value displayed to be "England - Paul".
Likewise for example typing in "David" would give "England - David".

Cand this be done in using VBA or cell formatting?

TIA.

--
NDB.

(Remove [nospam] from e-mail address when corresponding by e-mail)






Excellent. Thanks Tom.


--
NDB.

(Remove [nospam] from e-mail address when corresponding by e-mail)



NDB

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
NDB,

You could use the custom format of

;;;"England - "@

But that would only affect how the value is displayed. But you could use

an
event to change the actual value - this example (below) will work on

column
A. Copy the code, right click on the cell tab and select "View Code" then
paste in the window that appears:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Application.EnableEvents = False
If Left(Target.Value, 10) < "England - " Then
Target.Value = "England - " & Target.Value
End If
Application.EnableEvents = True
End If
End Sub

HTH,
Bernie
MS Excel MVP


"NDB" wrote in message
...
Hi,

I'm looking for a way to implement this ...

When a user selects cell A1 and enters a value (text), I would like the
displayed text to display a prefix also.

How can this be achieved?

eg. If user types in cell A1 the text value "Paul", when the enter key

is
pressed, I would like the cell value displayed to be "England - Paul".
Likewise for example typing in "David" would give "England - David".

Cand this be done in using VBA or cell formatting?

TIA.

--
NDB.

(Remove [nospam] from e-mail address when corresponding by e-mail)






And thanks to you too Bernie.


--
NDB.

(Remove [nospam] from e-mail address when corresponding by e-mail)




All times are GMT +1. The time now is 08:42 PM.

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