Adding Dashes in a query

Moxioron

Active Member
Joined
Mar 17, 2008
Messages
436
Office Version
  1. 2019
Hello all.

I have a 16 digit account number that I want to add dashes to.

CardWithDashes: Left([CardNumber],4) & '-' & Mid([CardNumber],4,4) & '-' & Mid([CardNumber],8,4) & '-' & Right([CardNumber],4)

It works fine except the third set of numbers seems to replace numbers with zeros.


So: 1234120000020555

Ends Up Being: 1234-1200-0000-0555

What am I missing? Thanks for your help.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You are starting your MIDs in the wrong places. If you want dashes after every four numbers, your startings points are 1, 5, 9, and 13.

CardWithDashes: Left([CardNumber],4) & '-' & Mid([CardNumber],5,4) & '-' & Mid([CardNumber],9,4) & '-' & Right([CardNumber],4)
 
Upvote 0
Good God...I figured it out myself. What a day! I have to learn to count one of these days!

CardWithDashes: Left([CardNumber],4) & '-' & Mid([CardNumber],5,4) & '-' & Mid([CardNumber],9,4) & '-' & Right([CardNumber],4)
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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