• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Extract Invoice Number to Number Format

sgmpatnaik

Active Member
Hi, Good Morning Every One

actually i am a tax Consultant and i have to cross check the books of records with GST , I have prepared one excel file to Reconcile the data from GST to Clients Data here i am facing an problem, that is i would like to extract the numbers of GST invoice to numbers format but i fail to ,so in this time i remember my family members
and i came here with full hope , i tried lots of function codes but i fail and finally i came here because here my teachers and ninjas are here, i hope you understand the issue and solves my problem

i would like to create a function code like GetInvoice_Number()

for your knowledge i have attached the Sample file

Thanking You

Mr. Patnaik
 

Attachments

Instead of a function ... could You use something like?
Your given data have many combinations/variations of ... two years ... or how?
My sample:
I collect those to E-column.
G-column shows my results.
If there are 'any challenges' ... those rows will mark in I-column.
Of course, Your used layout needs to take care.
Usage: press [ Do It ]-button
 

Attachments

Instead of a function ... could You use something like?
Your given data have many combinations/variations of ... two years ... or how?
My sample:
I collect those to E-column.
G-column shows my results.
If there are 'any challenges' ... those rows will mark in I-column.
Of course, Your used layout needs to take care.
Usage: press [ Do It ]-button
Hi, sorry for my delay replay. i completely gone through your sample file and i checked there you have taken a helper column E there we have to mention the ignore methods to get the invoice number, after that if we run the code which you given the button do it then it extract the invoice numbers base with Column E then we are getting the Invoice Numbers exactly, but it is difficult to mark the Column E for Away records when the records are 1k + another point is if we have any work pressure on that time we can mention the Away Records but it is highly impossible when we have a work load. Actually i write a code for get the Numbers to extract but that is not extracting for 100 %

For your knowledge i have attached the same file and mentioned the results in Sheet 2, at present i mentioned the wrong generating numbers in the column F to I

i am waiting for the perfect result or any good suggestion from you and my old Teachers

Thanking You
 

Attachments

That was a sample.
A helper column can be ... any free column!
... even extraction column could be same as 'source' (Your A-column).
What is ... difficult?
There could be ... any number of data and so on.
I modified my sample based my previous sample.
 

Attachments

Here i am running a code for Data Reconciliation with sheets that's why i want a function code for GetInvoice Number

hope you understand

Thank You


Option Explicit
Sub New_FINAL_RECON_AUDIT_PROOF()
Dim wsPR As Worksheet, ws2B As Worksheet
Dim wsRec As Worksheet, wsMatch As Worksheet, wsNotMatch As Worksheet


Set wsPR = Sheets("Purchase_Register")
Set ws2B = Sheets("GSTR-2B_Data")
Set wsRec = Sheets("Reconciliation")
Set wsMatch = Sheets("Matched_Data")
Set wsNotMatch = Sheets("Not_Matched")


' Clear old data
wsRec.Cells.Clear
wsMatch.Cells.Clear
wsNotMatch.Cells.Clear


' Headers
wsRec.Range("A1:H1") = Array("GSTIN", "Supplier", "Invoice", "Books Total", "2B Total", "Diff", "Status", "Remarks")
wsMatch.Range("A1:G1") = Array("GSTIN", "Supplier", "Invoice", "Books", "2B", "Status", "Type")
wsNotMatch.Range("A1:G1") = Array("GSTIN", "Supplier", "Invoice", "Books", "2B", "Status", "Reason")

' Header Formatting (ONLY HEADER)
With wsRec.Range("A1:H1")
.Font.Bold = True
.Interior.Color = RGB(0, 112, 192)
.Font.Color = RGB(255, 255, 255)
End With

' ===============================
' BUILD BOOKS DICTIONARY (GROUPED)
' ===============================
Dim dictBooks As Object
Set dictBooks = CreateObject("Scripting.Dictionary")

Dim i As Long
Dim key As Variant

For i = 2 To wsPR.Cells(wsPR.Rows.count, 1).End(xlUp).Row

Dim gst As String, inv As String
Dim valB As Double, supplier As String

gst = UCase(Trim(wsPR.Cells(i, 1).Value))
supplier = wsPR.Cells(i, 2).Value
'inv = NormalizeInvoice(wsPR.Cells(i, 3).Value)
inv = GetInvoiceNumber_Final(wsPR.Cells(i, 3).Value)
If Trim(inv) = "" Then GoTo NextBooksRow

valB = GetTaxValue_new(wsPR, i)

key = gst & "|" & inv

If dictBooks.exists(key) Then
dictBooks(key)(0) = dictBooks(key)(0) + valB
Else
'dictBooks.Add key, Array(valB, supplier, gst, inv) this is changed by me now
dictBooks.Add key, Array(valB, supplier, gst, inv, 1)
If dictBooks.exists(key) Then
dictBooks(key)(0) = dictBooks(key)(0) + valB
dictBooks(key)(4) = dictBooks(key)(4) + 1 ' ?? count
Else
dictBooks.Add key, Array(valB, supplier, gst, inv, 1)
End If
End If
NextBooksRow:
Next i

' ===============================
' PROCESS 2B DATA
' ===============================
Dim rowRec As Long: rowRec = 2
Dim rowM As Long: rowM = 2
Dim rowN As Long: rowN = 2

For i = 2 To ws2B.Cells(ws2B.Rows.count, 1).End(xlUp).Row

Dim gst2B As String, inv2B As String
Dim val2B As Double

gst2B = UCase(Trim(ws2B.Cells(i, 1).Value))
'inv2B = NormalizeInvoice(ws2B.Cells(i, 3).Value)
inv2B = GetInvoiceNumber_Final(ws2B.Cells(i, 3).Value)

If Trim(inv2B) = "" Then
wsRec.Cells(rowRec, 1) = gst2B
wsRec.Cells(rowRec, 2) = ws2B.Cells(i, 2).Value
wsRec.Cells(rowRec, 3) = ws2B.Cells(i, 3).Value
wsRec.Cells(rowRec, 7) = "Invalid"
wsRec.Cells(rowRec, 8) = "Invoice Format Error"

rowRec = rowRec + 1
GoTo Next2BRow

End If

val2B = val(ws2B.Cells(i, 6)) + val(ws2B.Cells(i, 7)) + val(ws2B.Cells(i, 8))

key = gst2B & "|" & inv2B

Dim booksVal As Double: booksVal = 0
Dim supplierName As String: supplierName = ""

If dictBooks.exists(key) Then
booksVal = dictBooks(key)(0)
supplierName = dictBooks(key)(1)
Else
' ? TAKE SUPPLIER FROM 2B WHEN NOT IN BOOKS
supplierName = ws2B.Cells(i, 2).Value
End If

Dim diff As Double
'diff = booksVal - val2B
diff = val2B - booksVal

Dim status As String, remark As String, mType As String

' ===============================
' ? FINAL CORRECT LOGIC
' ===============================

If dictBooks.exists(key) Then

If Abs(diff) <= 1 Then

status = "Matched"

' ?? CHECK SPLIT
If dictBooks(key)(4) > 1 Then
remark = "OK (Split Invoice)"
mType = "Split Match"
Else
remark = "OK"
mType = "Exact Match"
End If

Else

status = "Mismatch"
remark = "Value Difference"
mType = "Invoice Match"

End If

Else

status = "Not Found"
remark = "Missing in Books"

End If

' ===============================
' RECONCILIATION OUTPUT
' ===============================
wsRec.Cells(rowRec, 1) = gst2B
wsRec.Cells(rowRec, 2) = supplierName
wsRec.Cells(rowRec, 3) = inv2B
wsRec.Cells(rowRec, 4) = booksVal
wsRec.Cells(rowRec, 5) = val2B
wsRec.Cells(rowRec, 6) = diff
wsRec.Cells(rowRec, 7) = status
wsRec.Cells(rowRec, 8) = remark

' ===============================
' COLOR LOGIC (FINAL CORRECT)
' ===============================
Dim rngRow As Range
Set rngRow = wsRec.Range(wsRec.Cells(rowRec, 1), wsRec.Cells(rowRec, 8))
' Reset formatting
rngRow.Font.Bold = False
rngRow.Font.ColorIndex = xlAutomatic
If status = "Matched" Then

If Trim(UCase(remark)) Like "OK*" Then

' ?? BLUE (Matched + OK)
rngRow.Font.Bold = True
rngRow.Font.Color = RGB(0, 0, 255)

End If

Else

' ?? RED (Issues)
rngRow.Font.Bold = True
rngRow.Font.Color = RGB(255, 0, 0)

End If

' ===============================
' MATCH / NOT MATCH SHEETS
' ===============================

If status = "Matched" Then

wsMatch.Cells(rowM, 1) = gst2B
wsMatch.Cells(rowM, 2) = supplierName
wsMatch.Cells(rowM, 3) = inv2B
wsMatch.Cells(rowM, 4) = booksVal
wsMatch.Cells(rowM, 5) = val2B
wsMatch.Cells(rowM, 6) = status
wsMatch.Cells(rowM, 7) = mType

rowM = rowM + 1

Else

wsNotMatch.Cells(rowN, 1) = gst2B
wsNotMatch.Cells(rowN, 2) = supplierName
wsNotMatch.Cells(rowN, 3) = inv2B
wsNotMatch.Cells(rowN, 4) = booksVal
wsNotMatch.Cells(rowN, 5) = val2B
wsNotMatch.Cells(rowN, 6) = status
wsNotMatch.Cells(rowN, 7) = remark

rowN = rowN + 1

End If

rowRec = rowRec + 1
Next2BRow:
Next i

MsgBox "Final Audit Report Ready", vbInformation

End Sub
 
If Your ... Invoice codes ... are in other column than A then
let me know - where are those? I can modify my code.

In the beginning of Your above ... code ...
You should add my code and
You could get those 'shorter version' in that column.
... which You could get without any ... functions.
if Your function won't work ... my code works...
if my guessed logic is as it should be.
... which You've skipped to verify.

Of course, You could modify my macro to Your function Yourself.
 
Hi past in new module this code; use the formula example =GetInvoice_Number(A2)
Code:
Function GetInvoice_Number(inv As String) As String
    Dim oRegex    As Object
    Dim oMatches  As Object
    Dim sParts()  As String
    Dim sResult   As String
    Dim sPart     As String
    Dim i As Integer, j As Integer
    Dim y1 As Integer, y2 As Integer
    Dim bIsFY As Boolean
    Dim nCount As Integer
    Dim sLast As String, sSecLast As String
    Dim sRemain As String

    Set oRegex = CreateObject("VBScript.RegExp")
    oRegex.Global = True

    inv = Trim(inv)
    If inv = "" Then GetInvoice_Number = "": Exit Function

    If InStr(inv, "/") > 0 Then
        sParts = Split(inv, "/")
        For i = UBound(sParts) To 0 Step -1
            sPart = Trim(sParts(i))
            bIsFY = False
            oRegex.Pattern = "^(\d{2,4})-(\d{2,4})$"
            If oRegex.Test(sPart) Then
                Set oMatches = oRegex.Execute(sPart)
                y1 = CInt(oMatches(0).SubMatches(0)) Mod 100
                y2 = CInt(oMatches(0).SubMatches(1)) Mod 100
                If y2 = (y1 + 1) Mod 100 Then bIsFY = True
            End If
            If Not bIsFY Then
                oRegex.Pattern = "\d+"
                If oRegex.Test(sPart) Then
                    Set oMatches = oRegex.Execute(sPart)
                    sResult = ""
                    For j = 0 To oMatches.Count - 1
                        sResult = sResult & oMatches(j).Value
                    Next j
                    GetInvoice_Number = sResult
                    Exit Function
                End If
            End If
        Next i
    Else
        sParts = Split(inv, "-")
        nCount = UBound(sParts) + 1
        oRegex.Pattern = "^\d{2,4}$"
        Do While nCount >= 2
            sLast    = Trim(sParts(nCount - 1))
            sSecLast = Trim(sParts(nCount - 2))
            If oRegex.Test(sLast) And oRegex.Test(sSecLast) Then
                y1 = CInt(sSecLast) Mod 100
                y2 = CInt(sLast) Mod 100
                If y2 = (y1 + 1) Mod 100 Then
                    nCount = nCount - 2
                Else
                    Exit Do
                End If
            Else
                Exit Do
            End If
        Loop
        sRemain = ""
        For i = 0 To nCount - 1
            If i > 0 Then sRemain = sRemain & "-"
            sRemain = sRemain & sParts(i)
        Next i
        oRegex.Pattern = "\d+"
        If oRegex.Test(sRemain) Then
            Set oMatches = oRegex.Execute(sRemain)
            sResult = ""
            For j = 0 To oMatches.Count - 1
                sResult = sResult & oMatches(j).Value
            Next j
            GetInvoice_Number = sResult
        Else
            GetInvoice_Number = ""
        End If
    End If

End Function
 

Attachments

Ah Great Work the both suggestions,

Thank You Friends for your support, i did my job with your support, if any help need then i will knock the door again

Thank You
 
@ Gateway2026

can you please help me to find out the mistake where i am doing, that is when i run the code with your given function then i am facing problem to sum the value of partial invoices which are located in the sheet of Purchase Register .

my Reconciliation code is compare the Data from GSTR 2B to Clients Purchase Register if any invoices are missed in 2B or Purchase register then i will extract the records in the Reconciliation Tabs

for your knowledge i have attached the file and also i filter the mistake one

your replay is highly appreciate
 

Attachments

Aha Thank You, at present the sum / Calculations are correct, Thank You, Can You do a favor for me, actually i am thinking to add the extra option and one another code that is at present we are doing the reconciliation with Tax Part Only now i would like to add one more extra line that is if the books Tax Values and B2B Tax Values are 0 and there is a Taxable values are there in the Books Records then in our Reconciliation Tab Status Column to be mention as Tax Free and in the remarks column Ok

2nd one i am thinking that is to do a New Code in our Reconciliation Tab in Column I Reconcile Head and when we update the records from the Status column which are marked as miss match, not found and not in 2B. Manually we will update the missing records when Column I Records converted to Match then automatically they marked with blue and copy to end of the last row in the Matched Tab

can you do this please, sorry if i gave you trouble

Thanking You
 
When you type MATCH (any case) in column I for any row:
  • The entire row turns bold blue immediately
  • Status column updates to "Matched", Remarks to "Manual Match"
  • The record is appended to the bottom of Matched_Data, also formatted blue
  • Row with tax 0 values are green.
 

Attachments

sgmpatnaik

If You would like to use my kind of function,
then below is one rough sample.
Code:
Function GetInvoice_Number(xit)
    gg = xit
    away = Split("INV26 /24-25 24-25/ /2024-25 /2526 2526/ /25-26 25-26 -25-26 /2025-2026", " ")
    For aa = LBound(away) To UBound(away)
        gg = WorksheetFunction.Substitute(gg, away(aa), "")
    Next aa
    ggg = Empty
    For b = Len(gg) To 1 Step -1
        bb = Mid(gg, b, 1)
        Select Case bb
            Case "A" To "Z", "/", "-"
                bb = ""
            End Select
        ggg = bb & ggg
    Next b
    GetInvoice_Number = ggg
End Function
I compared its results with my 'macro's results.
 
@Gateway2026

Good Morning, Thank You For Your Support and it's works perfect as i think, i feel very glad

@vletm

Good Morning, Thank You for Your Replay, at present i have not tested your code but sure i will test and inform you the same, can you please elaborate how it is handle the extract only invoice numbers

Thanking You All for your Great Support
 
Those steps could find based Your given sample data and Your given sample expected results.
#1 step: away is collection of text which should hide
#2 step: find all those letters and / & - ... which should hide.
#3 step: the rest part is Your invoice number
It is a rough example of function.
... which could be shorter eg if away would be out of this function.
 
@Gateway2026

Hi i need one suggestion from you that is when i am doing the reconciliation for the clients then i noticed one thing that is if there is single invoice entered multiply times for same value then it's summing but i am thinking some different, for your knowledge i have explain the same in the sample file please check , i have marked with yellow for invoice numbers and filtered please check the GSTR 2 tab and Purchase_Register Tab with that you will get some idea

Your Reply is highly appreciate

Thanking You
 

Attachments

Hi, Good Morning, we got 95 % success the 5 % is missed, i am explaining you clearly that is we entered the invoices 3476, and 3477 in two times and the invoice totals are not matched with the 2B figures so we marked with mismatch and Multi Entries found.
the Invoice Number 3840 also entered in multi times but when we sum that invoice number 3840 and it's totals match with GSTR 2B then it should be mark with Match and in remarks as Ok or Multi Entries - Match Like This

example

INV 3476 200.00
INV 3476 220.00

IN GSTR 2B

INV 3476 200.00

then the result

INV 3476 200.00 200.00 Match Ok
INV 3476 220.00 200.00 mismatch Duplicate Entry

and another sample

INV 3840 105.00
INV 3840 95.00

IN GSTR 2B

INV 3840 200.00

then the result

INV 3840 200.00 200.00 Match Ok - Multi Entries

and i am confused when there is no double entries for some invoices and it's figures are differed from books to 2B then why it's comes as Multiple Entries – No Exact Match instead of Value Difference or some thing else

Please Check
 
Gateway2026

Thanks for Your Support and kind heart, i have downloaded the file which you given me i will check to day night because i have some pending returns to complete them

and just i checked not gone through

Code:
21AADFK6145K1ZG    Kausalya Agencies    3840    1235.52    1595.52    -360    Matched    OK
21AADFK6145K1ZG    Kausalya Agencies    3840     360.00                360    Matched    OK

What we can't add that type of results into one like

Code:
21AADFK6145K1ZG    Kausalya Agencies    3840    1595.52    1595.52    -360    Matched    OK (Partial Bills)

if not possible then don't worry, because you supported me a lot

just i checked that part only to day night i will check that fully if any issue then i will knock your door and please open the door with smile for me

Thanking You

Yours Patnaik
 
Back
Top