ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Input masks in Excel (https://www.excelbanter.com/excel-discussion-misc-queries/114616-input-masks-excel.html)

Chris

Input masks in Excel
 
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

Input masks in Excel
 
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

On Mon, 16 Oct 2006 10:16:03 -0700, Chris
wrote:

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


All times are GMT +1. The time now is 11:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com