Add a prefix to a cell

  • Thread starter Thread starter Decreenisi
  • Start date Start date
D

Decreenisi

Dear all

I have a large excel (Office 07) spreadsheet, which I enter reject
data everyday. In Column P i have to enter a sticker number such as
S132453. The number always starts with a capital S then 6 numbers. Is
there anyway that when I click into the cell, it automatically enters
an "S" then allows me to type the numbers. I also need to be able to
sort data by sticker number and use a macro to search the spreadsheet
to find specific numbers. Can anyone help

Thanks
 
Try this small Event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set r = Range("P:P")
If Intersect(t, r) Is Nothing Then Exit Sub
If Left(t.Value, 1) = "S" Then Exit Sub
Application.EnableEvents = False
t.Value = "S" & t.Value
Application.EnableEvents = True
End Sub

This will add the "S" for you. If you already have entered an "S" or are
editting old data, it not add an extra "S"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top