Input masks in Excel

G

Guest

Hello,

I would like to set up an input mask in Excel for a Canadian Postal code
(e.g. T7G 8R4). I am not sure how to do this.
 
G

Gord Dibben

Chris

There is no Custom Format for Canadian Postal codes that I have found.

You can use event code in the worksheet so that as you enter the code, it will
change to A1A 1A1

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column <> 1 Then Exit Sub
On Error GoTo ErrHandler
Application.EnableEvents = False
With Target
.Formula = UCase(Target.Formula)
.Value = (Left(Target.Value, 3) & " " & Right(Target.Value, 3))
End With
ErrHandler:
Application.EnableEvents = True
End Sub

As written this event code operates on Column A only.

You can type the code in as upper or lower case. Will come out as upper case no
matter what.

Right-click on the sheet tab and "View Code"

Copy/paste the above into that sheet module.

Adjust for your column if needed.

i.e. for just column B edit to If Target.Column <> 2 Then Exit Sub


Gord Dibben MS Excel MVP..................and Canuck

Hello,

I would like to set up an input mask in Excel for a Canadian Postal code
(e.g. T7G 8R4). I am not sure how to do this.

Gord Dibben MS Excel MVP
 

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

Similar Threads

Cdn Postal Code 3
Multiple Input Masks? 1
Input masks 4
Input masks 1
Conditional Input Mask 2
Creating Custom MS-Access Input Masks 0
Input Masks 1
Validate Canadian Postal codes in Excel 1

Top