Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 647
  • Last Modified:

Custom Input Masks for Excel

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
Shanan212
Asked:
Shanan212
  • 14
  • 10
1 Solution
 
gowflowCommented:
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
 
Shanan212Author Commented:
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
 
gowflowCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Shanan212Author Commented:
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
 
gowflowCommented:
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
 
Shanan212Author Commented:
Thanks!
0
 
gowflowCommented:
Thank you, but may I ask why you rated Good ??? Are you not satissfied with the answer ? Did I miss something ?
gowlfow
0
 
Shanan212Author Commented:
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
 
gowflowCommented:
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
 
gowflowCommented:
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
 
Shanan212Author Commented:
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
 
gowflowCommented:
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
 
Shanan212Author Commented:
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
 
gowflowCommented:
Try this
gowflow
T21.xls
0
 
gowflowCommented:
Did you try the last file ? Pls do not be afraid to request more adjustments I have no problem at all.
gowflow
0
 
Shanan212Author Commented:
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
 
gowflowCommented:
Is that what you want ?
gowflow
T21.xls
0
 
Shanan212Author Commented:
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
 
gowflowCommented:
Keep throwing ... I like it !!
try this
gowflow
T21.xls
0
 
gowflowCommented:
I am afraid to ask you for a feedback ... did I hit it or again missed it ?

gowflow
0
 
Shanan212Author Commented:
Ok. This is exactly what I wanted :)

How can I reassign points!?

Thanks!
0
 
gowflowCommented:
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
 
Shanan212Author Commented:
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
 
gowflowCommented:
no problem. take care.
gowflow
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 14
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now