Adding Dashes in a query

Moxioron

Active Member
Joined
Mar 17, 2008
Messages
420
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.
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,916
Office Version
  1. 365
Platform
  1. Windows
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)
 

Moxioron

Active Member
Joined
Mar 17, 2008
Messages
420
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,606
Messages
5,597,134
Members
414,128
Latest member
Jorglo

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
Top