Solved

Custom Input Masks for Excel

Posted on 2013-01-17
24
618 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 13

Author Comment

by:Shanan212
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0
 
LVL 29

Expert Comment

by:gowflow
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 13

Author Comment

by:Shanan212
Comment Utility
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
Comment Utility
Try this
gowflow
T21.xls
0
 
LVL 29

Expert Comment

by:gowflow
Comment Utility
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
Comment Utility
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
Comment Utility
Is that what you want ?
gowflow
T21.xls
0
 
LVL 13

Author Comment

by:Shanan212
Comment Utility
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
Comment Utility
Keep throwing ... I like it !!
try this
gowflow
T21.xls
0
 
LVL 29

Expert Comment

by:gowflow
Comment Utility
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
Comment Utility
Ok. This is exactly what I wanted :)

How can I reassign points!?

Thanks!
0
 
LVL 29

Expert Comment

by:gowflow
Comment Utility
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
Comment Utility
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
Comment Utility
no problem. take care.
gowflow
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now