Solved

Custom Input Masks for Excel

Posted on 2013-01-17
24
630 Views
Last Modified: 2013-01-25
Hi,

I have a user code which always starts with "T21"...it can be T2112JSA2 (or any # of digits/letters after the initial "T21"

How do I set this as the input mask for a field?

I want it such that, when user double clicks on cell A2 (or clicks on A2 and then formula bar), the "T21" should be already there

Is this possible? If then how?

Thanks!
0
Comment
Question by:Shanan212
  • 14
  • 10
24 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 38788341
you oonly wanted on cell A2 ? then put this code

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = "$A$2" Then
Target.Value = "T21"
End If
End Sub

Open in new window



gowflow
0
 
LVL 13

Author Comment

by:Shanan212
ID: 38788376
Thanks GowFlow,

The problem is, the code can be anything after T21 though; its not limited to T21

I have a user code which always starts with "T21"...it can be T2112JSA2 (or any # of digits/letters after the initial "T21"
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38788409
you said doubleclik and show T21 !!!!
I am not testing what is in A2 what do you need I do not understand your comment

Thinking more about it do you want the user to put any code and then for it to append T21 in the beggining ???

then the code would be:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
Application.EnableEvents = False
Target.Value = "T21" & Target.Value
Application.EnableEvents = True
End If
End Sub

Open in new window



gowflow
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 13

Author Comment

by:Shanan212
ID: 38788630
The user would put in only the underlined code

T21S9021S33

I want the T21 to be there beforehand (but only when the cell is double clicked/selected via formula bar) Otherwise, the cell would remain empty
0
 
LVL 29

Accepted Solution

by:
gowflow earned 400 total points
ID: 38788719
ok try this
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = "$A$2" Then
Application.EnableEvents = False
If Target.Value <> "" Then Target.Value = "T21" & Target.Value
Application.EnableEvents = True
End If
End Sub

Open in new window


NOTE Make sure oyu only want this in Cell A2 as this is how it is doing if you need all cells in Col A then will need to modify this.

Chk the ifle posted and put any value in A2 and then doubleclik on it.
gowdlow
T21.xls
0
 
LVL 13

Author Closing Comment

by:Shanan212
ID: 38811419
Thanks!
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38811444
Thank you, but may I ask why you rated Good ??? Are you not satissfied with the answer ? Did I miss something ?
gowlfow
0
 
LVL 13

Author Comment

by:Shanan212
ID: 38811483
Hi gowflow,

I want to thank you again. I don't want to deter you from answering my questions in future.

its just that sub had its problems as it adds the 'T21' after

- a value is entered then
- a double click is made

Another problem is, further double clicks continues to add 'T21'

However, based on my little knowledge, I adjusted  some problems but later abandoned doing it.
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38811507
well you just need to tell me !!!!! what am I doing here ???? looking for points ??? not at all your totally mistaken !! My aim is to provide a 100% working solution nothing less.

Let me look at it and will revert.
gowflow
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38811517
So let me get this right what is wrong that need to be fixed beside adding T21 each time it is doubleclicked ??

Attached is fixing for multiple T21. Tell me what else need to be fixed.
gowflow
T21.xls
0
 
LVL 13

Author Comment

by:Shanan212
ID: 38811544
Well,

I wanted it to be pre-populated. The current sub does not do it till I repeat the steps I mentioned above.

Whether the user chooses to input by double cliking/via formula bar, the user should know that 'T21' is already there and that there is no need to re-enter it.
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38812116
so let me summarize:
You want if the user enter a digit 456 and press enter to have T21456
and if there 345 in the cell and he doubleclick to have T21345
and if there is T21345 and he doubleclick to have still T21345

is that what you want ?
gowflow
0
 
LVL 13

Author Comment

by:Shanan212
ID: 38812130
Nope!

I want to have 'T21' pre-populated if he

double clicks an empty cell (with the intention to enter something after T21)
OR
single clicks on the cell and then clicks on the formula bar (to enter something via there)
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38812143
Try this
gowflow
T21.xls
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38813357
Did you try the last file ? Pls do not be afraid to request more adjustments I have no problem at all.
gowflow
0
 
LVL 13

Author Comment

by:Shanan212
ID: 38814376
Hi gowflow,

This is the sub I wanted for double click. I slighly modified it

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = "$A$2" Then

If Target.Value = "" Then
Target.Value = "T21" & Target.Value
End If
end if
end sub

Open in new window


However, this partially solves the problem.

There are other ways a user may try to access a cell. By changing focus from (say) A1 to A2 OR single clicking on A2 and then clicking on formula bar.

In both of above cases, I want a result similar to the double-click sub above. That is, I want the T21 appear there.
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38815133
Is that what you want ?
gowflow
T21.xls
0
 
LVL 13

Author Comment

by:Shanan212
ID: 38815154
Hi Gowflow,

Thats exactly what I want with one more thing. The user could potentially not enter anything at all (and goto different line), at which case, I want to the cell to be empty.
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38815357
Keep throwing ... I like it !!
try this
gowflow
T21.xls
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38818422
I am afraid to ask you for a feedback ... did I hit it or again missed it ?

gowflow
0
 
LVL 13

Author Comment

by:Shanan212
ID: 38819448
Ok. This is exactly what I wanted :)

How can I reassign points!?

Thanks!
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38819785
No need. don't worry as long as you are fully satissfied, I am. Let me know if u need more help in other issue, I'll be glad to assit.
gowflow
0
 
LVL 13

Author Comment

by:Shanan212
ID: 38819793
Nope thats all!

I thought this cannot be done based on the multiple ways there were to edit a cell (eg: double click, single click then formula bar, single click then pressing F2, etc)

But I guess we can!

Thanks for the help all the way!
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38819912
no problem. take care.
gowflow
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question