postcode format Netherlands

wimven

New Member
Joined
Feb 1, 2010
Messages
14
Please,

Can someone help me to the VBA lines for the entry field txtPostcd in a userform which should give the format:

4 digits, space, 2 letters
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Thanks for you quick reply Krishni but this does not answer my question; the 4 on the left can only be digits en the two on the right just letters.
And it has to be written in vba as well.
I have searched the www but did not come up with an answer. However, it seems so much easier than the postcodes in the UK
 
Upvote 0
Try:

Code:
Private Sub CommandButton1_Click()
    With TextBox1
        If Not .Text Like "[0-9][0-9][0-9][0-9] [A-Z][A-Z]" Then
            MsgBox "Invalid"
        End If
    End With
End Sub
 
Upvote 0
I am not sure if i understand what you mean by that Andrew but i guess this is why i posted that it's from a userform.
 
Upvote 0
I am not sure if i understand what you mean by that Andrew but i guess this is why i posted that it's from a userform.
Take Andrew's code and swap the name of the textbox with the name you mention in the OP.
Like so:
Code:
Private Sub CommandButton1_Click()
    With txtPostcd
        If Not .Text Like "[0-9][0-9][0-9][0-9] [A-Z][A-Z]" Then
            MsgBox "Invalid"
        End If
    End With
End Sub</pre>
 
Upvote 0
no matter what or where, i keep getting "invalid"
So you have a userform.

Can you give us the name of the field on the userform, also this code needs to be on the userform.

If you have placed the button on the sheet then it might work with
Code:
With Userform1.txtPostcd
</pre>
or replace userform1 with whatever your userform is called.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top