Solved

Custom Input Masks for Excel

Posted on 2013-01-17
24
627 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

810 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