TallyPrime ready · One-time price
0
Blog › Excel VBA › Excel Formula to Validate GSTIN Before…← All posts
Excel Formula to Validate GSTIN Before Importing to TallyExcel VBA
Excel VBA27 Nov 20266 min read

Excel Formula to Validate GSTIN Before Importing to Tally

LW
LearnWell teamE2T.in · Tally & TDL developers

You get a party list in Excel from a client or a sales team, and you need to import it into TallyPrime as ledgers. Half the GSTINs have spaces, some are in small letters, a few have 14 characters and one or two are just wrong. If these go into Tally as they are, you will find the problem later in GSTR-1, when the return does not match.

This post shows how to check GSTIN format in Excel before import, using simple formulas and one short VBA function. It takes a few minutes to set up and you can reuse the same sheet every month.

What a correct GSTIN looks like

A GSTIN has exactly 15 characters. For a normal registered business, the structure is:

  • Characters 1 to 2: State code (two digits).
  • Characters 3 to 12: PAN of the business (5 letters, 4 digits, 1 letter).
  • Character 13: Entity number for the same PAN in that state (1 to 9, then A to Z).
  • Character 14: Usually the letter Z.
  • Character 15: Check character (a digit or a letter).

So a GSTIN like 27ABCDE1234F1Z5 follows the pattern. Excel can check this pattern for you. What Excel cannot tell you is whether the GSTIN is actually active on the GST portal. For that, you still need to search it on the portal. Our checks only catch typing and format mistakes, which is where most import errors come from.

Step 1: Clean the GSTIN column

Most GSTIN problems are not wrong numbers. They are extra spaces, line breaks and small letters copied from emails or PDFs. Clean these first.

Say your raw GSTINs are in column A, starting from A2. In B2, enter this formula and fill it down:

=UPPER(SUBSTITUTE(SUBSTITUTE(CLEAN(A2)," ",""),CHAR(160),""))

What it does:

  • CLEAN removes line breaks and other hidden characters.
  • The first SUBSTITUTE removes normal spaces, including spaces in the middle.
  • The second SUBSTITUTE removes CHAR(160), the non-breaking space that often comes with data copied from websites and PDFs. TRIM does not remove this one.
  • UPPER converts everything to capital letters.

From now on, work only with column B.

Step 2: Check the length

In C2, enter:

=LEN(B2)=15

This shows TRUE or FALSE. Any FALSE row has a missing or extra character. Filter column C on FALSE and fix those rows first, because the other checks depend on the length being right.

Step 3: Check the full pattern

There are two ways to do this. Use the one that works in your Excel.

Option A: REGEXTEST (newer Microsoft 365)

Newer versions of Microsoft 365 have a REGEXTEST function. If you type =REGEXTEST( and Excel shows the function, you can use it. In D2, enter:

=REGEXTEST(B2,"^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$")

It returns TRUE only when the whole GSTIN follows the pattern: 2 digits, 5 letters, 4 digits, 1 letter, entity number, Z, and the last character. The ^ and $ make sure nothing extra is at the start or end.

Option B: A small VBA function (works in older Excel)

If you use Excel 2016, 2019 or another version without REGEXTEST, a short VBA function does the same job. Please try this in a copy of your file first, not on the original.

  1. Press Alt + F11 to open the VBA editor.
  2. Go to Insert > Module.
  3. Paste the code below into the module.
  4. Close the editor and come back to the sheet.
  5. Save the file as Excel Macro-Enabled Workbook (.xlsm), otherwise the code will be lost.
Function IsGSTINFormat(ByVal g As String) As Boolean
    g = UCase$(Replace(Trim$(g), " ", ""))
    IsGSTINFormat = (Len(g) = 15) And _
        (g Like "##[A-Z][A-Z][A-Z][A-Z][A-Z]####[A-Z][1-9A-Z]Z[0-9A-Z]")
End Function

Now in D2, use it like any normal formula:

=IsGSTINFormat(B2)

In VBA, Like checks text against a pattern. # means any single digit and [A-Z] means any single capital letter. Because the function converts the text to capitals first, small letters in the input will not cause a FALSE.

Step 4: Pull out state code and PAN for a quick cross-check

A GSTIN can pass the pattern test and still be wrong for that party, for example when two digits are swapped. Two extra columns help you spot this.

State code in E2:

=LEFT(B2,2)

PAN in F2:

=MID(B2,3,10)

Now compare the state code with the party’s address. If the party is in Maharashtra but the GSTIN starts with a different state code, check it again. If you also have the party’s PAN in another column, compare it with column F. A mismatch here is a strong sign of a typing error.

Step 5: Find duplicate GSTINs

The same party often appears twice in a list with slightly different names. If both get imported, you end up with two ledgers for one GSTIN. In G2, enter:

=COUNTIF($B$2:$B$1000,B2)>1

Change 1000 to the last row of your data. TRUE means the GSTIN appears more than once. Decide which name to keep before you import.

Step 6: Mark the rows that are ready to import

Finally, put everything together in one status column. In H2:

=IF(B2="","No GSTIN",IF(AND(C2,D2,NOT(G2)),"OK","Check"))

Blank GSTINs show “No GSTIN”, which is fine for unregistered parties. Every row marked “Check” needs a look before import. Filter on “OK” and copy only those rows to your import sheet.

Once the list is clean, you can import it using the method you already follow. If you are new to this, our post on free Excel to Tally import is a good place to start, and the Excel to Tally XML post explains the XML route. If you import regularly, you can also look at Excel to TallyPrime Import Automation – All in One.

Common mistakes

  • Fixing column A instead of column B. Keep the raw data as it is, so you can always go back and check what the client actually sent.
  • Trusting TRUE as “valid GSTIN”. The format check does not confirm that the GSTIN exists or is active. For new or doubtful parties, search the GSTIN on the GST portal.
  • Special registrations. Some special types of registration (for example UIN holders and certain non-resident or online service registrations) may not follow the normal pattern. If one of these shows “Check”, verify it on the portal instead of changing it.
  • Leading zero lost. If a GSTIN was typed into a cell formatted as a number at some point, the state code zero may already be gone (like 7 instead of 07). The length check will catch this.
  • Forgetting the .xlsm format. If you save as normal .xlsx, the VBA function is removed and column D shows #NAME?.

Why this matters inside Tally

A wrong GSTIN in a party ledger does not stop you from making entries, so it goes unnoticed. It shows up when you file GSTR-1 and your customer cannot see the invoice, or when the return shows exceptions. Cleaning the data before import saves you from correcting each ledger later. For other reasons GST reports show errors, see our guide on how to fix GST errors in Tally. And if you want GSTIN and mobile number visible while making vouchers, this TDL to show GST and mobile number in the voucher screen helps you spot mistakes during entry too.

Wrapping up

Clean, check length, check pattern, cross-check state and PAN, remove duplicates. Set up these columns once, save the sheet as a template, and paste each new party list into column A. Your Tally ledgers will start with clean GSTINs, and your GST returns will have fewer surprises.

Have a question about this sheet or about importing parties into TallyPrime? Message us on WhatsApp at +91 91318 10293.

Need this done for your business?

Our software imports Excel into TallyPrime in one click. Ask us for a free demo.

WhatsApp +91 91318 10293

Leave a Reply

Your email address will not be published. Required fields are marked *