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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
75TW14554TW145TW14 5TW145JS
53W1232W12W1 2W12BD
64W11543W115W11 5W115AC
LENfirst "n"NEW LENPOS OFFIRSTNEXTCONCAT
requiredREQ'DBLOCKCHARCOLS
SPACEF AND G
WITH
SPACE
BETWEEN
THIS shows the logic
are you adhering to this logic ?

<colgroup><col width="64" span="16" style="*******48pt"> </colgroup><tbody>
</tbody>
 
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,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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