Sub GetMasterData()
'
Application.ScreenUpdating = False ' Turn ScreenUpdating off
Application.DisplayAlerts = False ' Turn DisplayAlerts off
'
Dim FoundStateMatch As Boolean
Dim ArrayRow As Long
Dim DestinationLastRow As Long
Dim StateCodesArrayRow As Long
Dim StateCodeToFind As String
Dim StateCodesArray As Variant
Dim VerifiedGSTIN_Array As Variant
Dim desWS As Worksheet
Dim srcWS As Worksheet
'
Set srcWS = Sheets("GSTIN Verified")
Set desWS = Sheets("MasterData")
'
DestinationLastRow = desWS.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row ' Find last used row in the destination sheet
'
StateCodesArray = Sheets("State codes").Range("A1:B" & Sheets("State codes").Range("A" & _
Sheets("State codes").Rows.Count).End(xlUp).Row) ' Save Columns A:B from 'State Codes' into 2D 1 Based StateCodesArray
'
VerifiedGSTIN_Array = srcWS.Range("D2:T" & srcWS.Range("D" & srcWS.Rows.Count).End(xlUp).Row) ' Save Columns D:T from 'GSTIN Verified' into 2D 1 Based VerifiedGSTIN_Array
'
ReDim DestinationArray(1 To UBound(VerifiedGSTIN_Array, 1), 1 To 10) As Variant ' Set the Row & Column size for DestinationArray
'
For ArrayRow = 1 To UBound(VerifiedGSTIN_Array, 1) ' Loop through rows of VerifiedGSTIN_Array
DestinationArray(ArrayRow, 1) = VerifiedGSTIN_Array(ArrayRow, 3) ' Save Column F value from 'GSTIN Verified' to Column B of 'MasterData'
DestinationArray(ArrayRow, 2) = "Sundry Creditors" ' Save 'Sundry Creditors' to Column C of 'MasterData'
DestinationArray(ArrayRow, 3) = VerifiedGSTIN_Array(ArrayRow, 1) ' Save Column D value from 'GSTIN Verified' to Column D of 'MasterData'
'
If DestinationArray(ArrayRow, 3) <> "" Then ' If column D of destination sheet is blank then ...
DestinationArray(ArrayRow, 4) = "Regular" ' Set column E of destination sheet to 'Regular'
'
StateCodeToFind = Left$(VerifiedGSTIN_Array(ArrayRow, 1), 2) ' Set StateCodeToFind to the first two characters of column D of 'GSTIN Verified'
'
FoundStateMatch = False ' Set FoundStateMatch flag to 'False'
'
For StateCodesArrayRow = 1 To UBound(StateCodesArray, 1) ' Loop through rows of StateCodesArray
If StateCodesArray(StateCodesArrayRow, 1) = StateCodeToFind Then ' If column A of 'State codes' = StateCodeToFind then ...
DestinationArray(ArrayRow, 5) = StateCodesArray(StateCodesArrayRow, 2) ' Save column B of 'State codes' to column F of destination sheet
FoundStateMatch = True ' Set FoundStateMatch flag to 'True'
Exit For ' Exit this For loop
End If
Next ' Loop back
'
If FoundStateMatch = False Then MsgBox StateCodeToFind & " does not exist in State Codes." ' If no state match was found then displays message
Else ' Else ...
DestinationArray(ArrayRow, 4) = "Unregistered" ' Set column E of destination sheet to 'Unregistered'
End If
'
DestinationArray(ArrayRow, 6) = VerifiedGSTIN_Array(ArrayRow, 14) ' Copy column Q from 'GSTIN Verified' to column G of destination sheet
DestinationArray(ArrayRow, 7) = VerifiedGSTIN_Array(ArrayRow, 15) ' Copy column R from 'GSTIN Verified' to column H of destination sheet
DestinationArray(ArrayRow, 8) = VerifiedGSTIN_Array(ArrayRow, 16) ' Copy column S from 'GSTIN Verified' to column I of destination sheet
DestinationArray(ArrayRow, 9) = VerifiedGSTIN_Array(ArrayRow, 17) ' Copy column T from 'GSTIN Verified' to column J of destination sheet
'
DestinationArray(ArrayRow, 10) = VerifiedGSTIN_Array(ArrayRow, 6) ' Copy column I from 'GSTIN Verified' to column K of destination sheet
Next ' Loop back
'
desWS.Range("B" & DestinationLastRow + 1).Resize(UBound(DestinationArray, 1), _
UBound(DestinationArray, 2)) = DestinationArray ' Display the DestinationArray to the destination range
'
Application.ScreenUpdating = True ' Turn ScreenUpdating back on
Application.DisplayAlerts = True ' Turn DisplayAlerts back on
End Sub