Guruprasad1987
Member
the column titled Gl accc is the gl account ( name would not be gl account same as i mentioned ). the curr ,currency refers to the currencies of the countryCan't work as there is no gl account column in Corebanking file !
the column titled Gl accc is the gl account ( name would not be gl account same as i mentioned ). the curr ,currency refers to the currencies of the countryCan't work as there is no gl account column in Corebanking file !
Private Sub Demo()
Const E = ";Extended Properties=""Excel 12.0;IMEX=1;HDR=No"""
Dim oCn As Object, P$, F$, N, V, VH, R&, T, W, H%(3), C%, K$, VA#()
P = ThisWorkbook.Path & "\"
F = Dir(P & "*.xlsx"): If F = "" Then Beep: Exit Sub
Me.UsedRange.Offset(1).Clear
[E2].Value = " Wait …"
N = Array([{"country*"}], [{"curr*"}], [{"gl acc*"}], [{"revenue","Non funded income","NFI"}])
P = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & P
Set oCn = CreateObject("ADODB.Connection")
With CreateObject("Scripting.Dictionary")
Do
oCn.Open P & F & E
With oCn.Execute("SELECT * FROM [Sheet1$]")
V = .GetRows
.Close
End With
oCn.Close
VH = Application.Index(V, , 1)
For R = 0 To 3
For Each T In N(R)
W = Application.Match(T, VH, 0)
If IsNumeric(W) Then H(R) = W - 1: Exit For
Next
If IsEmpty(T) Then Exit For
Next
If T > "" Then
C = -(F Like "Corebanking*")
For R = 1 To UBound(V, 2)
K = V(0, R) & vbTab & V(H(0), R) & vbTab & V(H(1), R) & vbTab & V(H(2), R)
If .Exists(K) Then VA = .Item(K) Else ReDim VA(1)
VA(C) = VA(C) + V(H(3), R)
.Item(K) = VA
Next
End If
F = Dir
Loop Until F = ""
R = .Count
Set oCn = Nothing
[A2].Resize(R).Value = Application.Transpose(.Keys)
[A2].Resize(R).TextToColumns Tab:=True
[E2:F2].Resize(R).Value = Application.Index(.Items, 0)
.RemoveAll
End With
With [A2:F2].Resize(R).Columns
.Item("E:G").NumberFormat = Cells(7).NumberFormat
.Item(8).NumberFormat = Cells(8).NumberFormat
.Item(7).Formula = "=F2-E2"
.Item(8).Formula = "=IF(F2=0,""-"",E2/F2)"
.Item(9).Formula = "=IF(E2=F2,""R"",""Not r"")&""econciled"""
.Item("G:I").Formula = .Item("G:I").Value
End With
End Sub
As in my first post in this thread I clearly asked about workbooks names, I can't waste time anymore,
you must fix & set a definitive context
You never mentionned this and never joined such worksheet ‼The blanks ones are valid ones also the Gl account number column the length of the accounts has possible cases of 18 digit in length . if the two workbooks does not have any currency or gl account still in the case the data should be in summary report as null .
In this case according to your last attachment,if the two workbooks does not have any currency or gl account still in the case the data should be in summary report as null.
Option Compare Text
Function VHeaders(W)
Dim F&, V, R&
On Error Resume Next
F = LBound(W, 2): If Err.Number Then Exit Function
V = Application.Index(W, , 1)
If Not IsArray(V) Then
ReDim V(UBound(W))
For R = LBound(W) To UBound(W): V(R) = W(R, F): Next
End If
VHeaders = V
End Function
Private Sub Demo()
Const D = "¤", E = ";Extended Properties=""Excel 12.0;IMEX=1;HDR=No"""
Dim oCn As Object, P$, F$, M$, N, V, VH, R&, T, W, H%(3), B%, C%, K$, VA#()
P = ThisWorkbook.Path & "\"
F = Dir(P & "*.xlsx"): If F = "" Then Beep: Exit Sub
Me.UsedRange.Offset(1).Clear
[E2].Value = " Wait …"
M = "Bad Headers :"
N = Array([{"country*"}], [{"curr*"}], [{"gl acc*"}], [{"revenue","Non funded income","NFI"}])
P = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & P
Set oCn = CreateObject("ADODB.Connection")
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
Do
oCn.Open P & F & E
With oCn.Execute("SELECT * FROM [Sheet1$]")
V = .GetRows
.Close
End With
oCn.Close
VH = VHeaders(V)
If IsArray(VH) Then
For R = 0 To 3
For Each T In N(R)
W = Application.Match(T, VH, 0)
If IsNumeric(W) Then H(R) = W - 1: Exit For
Next
If IsEmpty(T) Then B = B + 1: M = M & D & F: Exit For
Next
If T > "" Then
C = -(F Like "corebanking*")
For R = 1 To UBound(V, 2)
K = V(0, R) & vbTab & V(H(0), R) & vbTab & V(H(1), R) & vbTab & V(H(2), R)
If .Exists(K) Then VA = .Item(K) Else ReDim VA(1)
If IsNumeric(V(H(3), R)) Then VA(C) = VA(C) + V(H(3), R)
.Item(K) = VA
Next
End If
Else
B = B + 1: M = M & D & F
End If
F = Dir
Loop Until F = ""
R = .Count
Set oCn = Nothing
[A2].Resize(R).Value = Application.Transpose(.Keys)
[A2].Resize(R).TextToColumns Tab:=True, FieldInfo:=Array([{1,2}], [{2,2}], [{3,2}], [{4,2}])
[E2:F2].Resize(R).Value = Application.Index(.Items, 0)
.RemoveAll
End With
With [A2:F2].Resize(R).Columns
.Item("E:G").NumberFormat = Cells(7).NumberFormat
.Item(8).NumberFormat = Cells(8).NumberFormat
.Item(7).Formula = "=F2-E2"
.Item(8).Formula = "=IF(F2=0,""-"",E2/F2)"
.Item(9).Formula = "=IF(E2=F2,""R"",""Not r"")&""econciled"""
.Item("G:I").Formula = .Item("G:I").Value
End With
If B Then
MsgBox "some bad headers workbook" & IIf(B > 1, "s", ""), vbExclamation, " Done but …"
V = Split(M, D)
[M2].Resize(UBound(V) + 1).Value = Application.Transpose(V)
End If
End Sub
Absolute perfect
Maybe now the mod code in my previous post is closed to perfect …