formatting cells

shacho

New Member
Joined
Mar 2, 2002
Messages
3
I want to be able to enter text in to any cell and automatically have my name as a prefex added on it, for example, if I enter the word "test" into a cell I would like it to look like to read
"tom-test" after I press enter, or if I enterd the word "blue" I would like it to read "tom-blue" after I press enter. Could someone tell me how to do this in Excel.

Thanx
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I think I already answered this for you at another site.

:smile:
 
Upvote 0
Pasted:

Requires this code:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing Then
Target(1).Value = "Tom-" & Target(1).Value
End If
Application.EnableEvents = True
End Sub


Change the range to that desired. Hit Alt-F11 and paste it into the code window for the desired sheet.
 
Upvote 0
Just copy from *sub* to *end sub* in my post above.

Open your Excel file.
Hit Alt-F11 to bring up the Visual Basic Editor (VBE).
On the top-left, double-click the sheet that you intend to have this trick work.
Make sure you see the code window at the right.
Click inside the code window and paste.
Change the range A1:A10 in my code to be the range that you want the code to work on, i.e., A:C to have it work on all columns A through C.

Close the VBE window.
Type something into the area that you have named above (A:C in my example) to test the code. If it works, save your file.
 
Upvote 0
That worked really good, thank you very much. There is one little thing more that I would like to do just to tweak this spead sheet a bit. Once I go into that cell what do I do if I want to delete it. The prefix still remains.
 
Upvote 0
That's a tough one that I cannot answer. Post in your question here before it drops to the bottom of the 2nd page each day to see if anyone else can help.

Sorry shacho.
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing Then
If Target.Value <> "" Then Target(1).Value = "Tom-" & Target(1).Value
End If
Application.EnableEvents = True
End Sub
 
Upvote 0
A VERY WELCOME to the board, Escalus. That's terrific!
 
Upvote 0

Forum statistics

Threads
1,223,516
Messages
6,172,777
Members
452,477
Latest member
DigDug2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top