Ms Query Data Type mismatch

swaink

Active Member
Joined
Feb 15, 2002
Messages
432
Hi All

I have a data set in an Excel Spreadsheet table and am querying that table from another workbook

In the data set I have a column showing the UK postcode with no space, I need to extract only the postcode down to sector level and add a space

In my query I have used select LEFT([Postcode],LEN([Postcode])-3) &" "& LEFT(RIGHT([Postcode],3),1) but I receive a Data Type mismatch in criteria expression error

For example TW145JS would look like TW14 5

I have tried searching for a clue to where I am going wrong without success and I wondered if anyone else has experienced this problem and is able to point me ion the right direction

Any help appreciated

Many thanks

Kevin
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
[TABLE="******* 1024"]
<colgroup><col width="64" span="16" style="*******48pt"> </colgroup><tbody>[TR]
[TD="******* 64, align: right"]7[/TD]
[TD="******* 64, align: right"]5[/TD]
[TD="******* 64"]TW145[/TD]
[TD="******* 64, align: right"]5[/TD]
[TD="******* 64, align: right"]4[/TD]
[TD="******* 64"]TW14[/TD]
[TD="******* 64"]5[/TD]
[TD="******* 64"]TW14 5[/TD]
[TD="******* 64"][/TD]
[TD="******* 64"][/TD]
[TD="******* 64"][/TD]
[TD="******* 64"][/TD]
[TD="******* 64"][/TD]
[TD="******* 64"][/TD]
[TD="******* 64"]TW145JS[/TD]
[TD="******* 64"][/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="align: right"]3[/TD]
[TD]W12[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]2[/TD]
[TD]W1[/TD]
[TD]2[/TD]
[TD]W1 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]W12BD[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[TD="align: right"]4[/TD]
[TD]W115[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]3[/TD]
[TD]W11[/TD]
[TD]5[/TD]
[TD]W11 5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]W115AC[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]LEN[/TD]
[TD]first "n"[/TD]
[TD][/TD]
[TD]NEW LEN[/TD]
[TD]POS OF[/TD]
[TD]FIRST[/TD]
[TD]NEXT[/TD]
[TD]CONCAT[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]required[/TD]
[TD][/TD]
[TD][/TD]
[TD]REQ'D[/TD]
[TD]BLOCK[/TD]
[TD]CHAR[/TD]
[TD]COLS[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]SPACE[/TD]
[TD][/TD]
[TD][/TD]
[TD]F AND G[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]WITH[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]SPACE[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]BETWEEN[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 2"]THIS shows the logic[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 3"]are you adhering to this logic ?[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Morning oldbrewer thanks for the reply

I have revisited the logic and it appears to be ok, I broke it down to just one piece LEFT([Postcode],LEN([Postcode])-3) this still shows the mismatch error
LEFT([Postcode],4) works fine, LEN([Postcode])-3 works ok its just doesn't work when I combine the two

Kev
 
Upvote 0
Do you have any blank postcodes, or shorter than 4 characters?
 
Upvote 0
Hi Rory

Yes there are some blanks and potentially there could be some less than four where the customer has not entered the correct postcode

Kev
 
Upvote 0
I think either of those could cause your problem since you'd be supplying a negative number of characters to take. Also, if you have values treated as Null, or errors, that would cause you problems, so you'll need to test for that.

For example, something like:

IIF(IsNull([PostCode],"",IIf(LEN([PostCode]<4,[Postcode],LEFT([Postcode],LEN([Postcode])-3) &" "& LEFT(RIGHT([Postcode],3),1)))
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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