VBA Excel code to automatically format text (Credit Card Numbers) based on length of string?Why does Excel...

Why does John Bercow say “unlock” after reading out the results of a vote?

Is it correct to write "is not focus on"?

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

How can I replace every global instance of "x[2]" with "x_2"

Generic lambda vs generic function give different behaviour

Failed to fetch jessie backports repository

Is it okay / does it make sense for another player to join a running game of Munchkin?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

The plural of 'stomach"

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Is there an Impartial Brexit Deal comparison site?

Is the destination of a commercial flight important for the pilot?

Is a roofing delivery truck likely to crack my driveway slab?

Should my PhD thesis be submitted under my legal name?

Was Spock the First Vulcan in Starfleet?

Bash method for viewing beginning and end of file

Applicability of Single Responsibility Principle

If you attempt to grapple an opponent that you are hidden from, do they roll at disadvantage?

Mapping a list into a phase plot

apt-get update is failing in debian

Why is delta-v is the most useful quantity for planning space travel?

What would happen if the UK refused to take part in EU Parliamentary elections?

What is the oldest known work of fiction?



VBA Excel code to automatically format text (Credit Card Numbers) based on length of string?


Why does Excel treat long numeric strings as scientific notation even after changing cell format to textFormat columns matching drop down value Excel 2003/VBAExcel - Convert dates and currency as text to Excel dates and numbers respectivelyVBA Code De-bugging in 2010 excelHow do I stop Excel from formatting numbers?Excel VBA filter String contains NumbersLocking and unlocking cells based on value in another cell for tablesExcluding text during VBA (Excel) RegEx searchWhy does the code permute delimitersExcel VBA for pulling apart text from a few cells and creating multiple cells of data













0















Background:




  1. Number formatted cells in Excel have digits beyond the 15th changed
    to zeros (reason). This behavior affects the recording
    of credit card numbers which can be longer than 15 digits. A work around to this behavior in Excel is to format cells that will contain credit card numbers (in advance of entering the data) as strings instead of numbers.

  2. To display this string in a more user-friendly format I add a helper
    column that takes the string and chunks it out.

  3. I do this by testing the length of the string and if it is 16
    characters I chunk it out as 4 4 4 4 (Canadian VISA/MC) and if it is 15 digits I chunk it out as 3 6 5 (Canadian Amex).
    Image  1:  Sample of my table        Image  2:  Formula I use to chunk in helper column


Question:

Can you adapt my worksheet code for VBA to dynamically apply the desired format to the column containing my credit card strings whenever the data changes? Image  3:  My table after adding requested VBA code










share|improve this question



























    0















    Background:




    1. Number formatted cells in Excel have digits beyond the 15th changed
      to zeros (reason). This behavior affects the recording
      of credit card numbers which can be longer than 15 digits. A work around to this behavior in Excel is to format cells that will contain credit card numbers (in advance of entering the data) as strings instead of numbers.

    2. To display this string in a more user-friendly format I add a helper
      column that takes the string and chunks it out.

    3. I do this by testing the length of the string and if it is 16
      characters I chunk it out as 4 4 4 4 (Canadian VISA/MC) and if it is 15 digits I chunk it out as 3 6 5 (Canadian Amex).
      Image  1:  Sample of my table        Image  2:  Formula I use to chunk in helper column


    Question:

    Can you adapt my worksheet code for VBA to dynamically apply the desired format to the column containing my credit card strings whenever the data changes? Image  3:  My table after adding requested VBA code










    share|improve this question

























      0












      0








      0








      Background:




      1. Number formatted cells in Excel have digits beyond the 15th changed
        to zeros (reason). This behavior affects the recording
        of credit card numbers which can be longer than 15 digits. A work around to this behavior in Excel is to format cells that will contain credit card numbers (in advance of entering the data) as strings instead of numbers.

      2. To display this string in a more user-friendly format I add a helper
        column that takes the string and chunks it out.

      3. I do this by testing the length of the string and if it is 16
        characters I chunk it out as 4 4 4 4 (Canadian VISA/MC) and if it is 15 digits I chunk it out as 3 6 5 (Canadian Amex).
        Image  1:  Sample of my table        Image  2:  Formula I use to chunk in helper column


      Question:

      Can you adapt my worksheet code for VBA to dynamically apply the desired format to the column containing my credit card strings whenever the data changes? Image  3:  My table after adding requested VBA code










      share|improve this question














      Background:




      1. Number formatted cells in Excel have digits beyond the 15th changed
        to zeros (reason). This behavior affects the recording
        of credit card numbers which can be longer than 15 digits. A work around to this behavior in Excel is to format cells that will contain credit card numbers (in advance of entering the data) as strings instead of numbers.

      2. To display this string in a more user-friendly format I add a helper
        column that takes the string and chunks it out.

      3. I do this by testing the length of the string and if it is 16
        characters I chunk it out as 4 4 4 4 (Canadian VISA/MC) and if it is 15 digits I chunk it out as 3 6 5 (Canadian Amex).
        Image  1:  Sample of my table        Image  2:  Formula I use to chunk in helper column


      Question:

      Can you adapt my worksheet code for VBA to dynamically apply the desired format to the column containing my credit card strings whenever the data changes? Image  3:  My table after adding requested VBA code







      microsoft-excel vba






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 11 mins ago









      Blind SpotsBlind Spots

      11




      11






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1418009%2fvba-excel-code-to-automatically-format-text-credit-card-numbers-based-on-lengt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1418009%2fvba-excel-code-to-automatically-format-text-credit-card-numbers-based-on-lengt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

          Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

          looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...