Compare, update or copy data from outside report - excel

I'm trying to compare a main planning file (let's call it Main.xlsm) and data that is provided by our ERP system (ERP.xlsm).
I'm looking to:
1) open a window to select the source file (ERP system dump).
2) compare unique ID values from column F in both files (Sheet RAPORT in Main.xlsm and Sheet1 in ERP.xlsm) and:
If there is a match between Main.xlsm and ERP.xlsm - update values in Main with values from ERP (all data - rows A:AK)
if there is an entry in ERP but no entry in Main - add the whole row with that ID (A:AK)
if there is an entry in Main but no data in ERP - place value "0" in row "R" in the Main file
Bonus round: Every time one of the above happens, place a time/date stamp in column "AL" in the row from the unique ID it altered.
I tried the code below (original version, not altered by me). I can't figure out how to achieve all from above.
Sub import_tickets()
'run this when the active file is the main ticket list and the active sheet is the ticket list
'exported file must be open already, and the ticket list must be the active sheet
Dim exported_file As String
exported_file = "exported file.xlsx"
header_exists = True 'if exported file doesn't have a header, set this to false!
starting_row = 1
If header_exists Then starting_row = 2
Dim first_blank_row As Long
first_blank_row = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0).Row
Dim r As Long
r = starting_row
Dim found As Range
cur_ticket_num = Workbooks(exported_file).ActiveSheet.Range("a" & r).Value
Do While Not cur_ticket_num = ""
'look for current ticket number in main file
Set found = Columns("a:a").Find(what:=cur_ticket_num, LookIn:=xlValues, lookat:=xlWhole)
If found Is Nothing Then
'add info to end of main file
write_line_from_export exported_file, r, first_blank_row
first_blank_row = first_blank_row + 1
Else
'overwrite existing line of main file
write_line_from_export exported_file, r, found.Row
End If
r = r + 1
cur_ticket_num = Workbooks(exported_file).ActiveSheet.Range("a" & r).Value
Loop
End Sub
Sub write_line_from_export(src_filename As String, src_r As Long, dest_r As Long)
For c = 1 To 24
Cells(dest_r, c).Value = Workbooks(src_filename).ActiveSheet.Cells(src_r, c).Value
Next c
End Sub

Here is an example that uses a Dictionary object to compare the ID column between the 2 sheets.
Sub import_tickets()
Dim sERPFileName As String
Dim wbERP As Workbook, wsERP As Worksheet
Dim wbMain As Workbook, wsMain As Worksheet
Dim r, startrow, lastrow As Long
Dim ID
Dim dictERP
Set dictERP = CreateObject("Scripting.Dictionary")
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Show
sERPFileName = .SelectedItems(1)
End With
Application.ScreenUpdating = False
' process ERP workbook
Set wbERP = Workbooks.Open(sERPFileName, , xlReadOnly)
Set wsERP = wbERP.Sheets("Sheet1")
startrow = 2 ' assume has header
lastrow = wsERP.Cells(Rows.Count, "F").End(xlUp).Row
For r = startrow To lastrow
ID = wsERP.Range("F" & r).Value
If dictERP.exists(ID) Then
MsgBox "Duplicate ID (" & ID & ") found in " & sERPFileName
Else
dictERP.Add ID, r
End If
Next r
' process MAIN workbook
Set wbMain = ThisWorkbook
Set wsMain = wbMain.Sheets("RAPORT")
startrow = 2 ' assume has header
lastrow = wsMain.Cells(Rows.Count, "F").End(xlUp).Row
For r = startrow To lastrow
ID = wsMain.Range("F" & r).Value
If dictERP.exists(ID) Then
' update
wsERP.Rows(dictERP(ID)).Columns("A:AK").Copy wsMain.Range("A" & r)
wsMain.Range("L" & r) = "Updated " & Now
dictERP.Remove (ID)
Else
' set col R = 0
wsMain.Range("R" & r).Value = 0
wsMain.Range("L" & r) = "No Change " & Now
End If
Next r
' add from ERP those not matched
If dictERP.Count > 0 Then
For Each ID In dictERP.keys
r = dictERP(ID)
lastrow = lastrow + 1
wsERP.Rows(r).Columns("A:AK").Copy wsMain.Range("A" & lastrow)
wsMain.Range("L" & lastrow) = "Added " & Now
Next
End If
wbERP.Close
Application.ScreenUpdating = True
If dictERP.Count Then
MsgBox dictERP.Count & " rows added"
Else
MsgBox "Done"
End If
End Sub

Related

How do you Format and Concatenate an Invoice or Bank Statement with Different Ranges in VBA

I have an invoice from a service provider that I need to format so I can use the data in Excel. But, the formatting is not consistent.
There are three (3) columns:
ID
Description
Amount
Many ID#s on the invoice have a one line (row) description.
But just as many have 2-11 lines (rows) of description.
The ID# is only listed once with each set of description lines.
Up to this point, I have used Excel Formulas. But, all my formulas is making things go very slow.
VBA would be way faster.
What I have done is created an index system looking for new ID#s.
Then I have created a cascading concatenate formula based on the given index system.
The amount has been easy to pull out using a LEFT formula, since the amount lists USD.
I then have a second sheet that does a VLOOKUP off of the first sheet to pull the ID's, final concatenated descriptions, and Amounts.
Our last invoice had 17,427 lines of data with only 1,717 ID#s.
Here is an example of what I am working with:
I want it to look like this:
one of the possible solutions below:
'assume that Id in column `A`, Description in column `B`, Amount in `C` and header in row 1
Sub somecode()
Dim wb As Workbook: Set wb = ActiveWorkbook
Dim sh As Worksheet: Set sh = wb.ActiveSheet
Dim lastRow&: lastRow = sh.Cells(Rows.Count, "B").End(xlUp).Row
Dim idColumn As Range: Set idColumn = sh.Range("A1:A" & lastRow)
Dim dic As Object: Set dic = CreateObject("Scripting.Dictionary")
Dim cl As Range, keyID, valueDescription$, valueAmount$
For Each cl In idColumn
If cl.Value <> "" And Not dic.exists(cl.Value) Then
dic.Add cl.Value, sh.Cells(cl.Row, "B").Value & "|" & sh.Cells(cl.Row, "C").Value
keyID = cl.Value
valueDescription = sh.Cells(cl.Row, "B").Value
valueAmount = sh.Cells(cl.Row, "C").Value
ElseIf cl.Value = "" Then
valueDescription = valueDescription & " " & sh.Cells(cl.Row, "B").Value
dic(keyID) = valueDescription & "|" & valueAmount
End If
Next cl
Set sh = wb.Sheets.Add: sh.Name = "Result " & Date & " " & Replace(Time(), ":", "-")
Dim dkey, xRow&: xRow = 1
For Each dkey In dic
sh.Cells(xRow, "A").Value = dkey
sh.Cells(xRow, "B").Value = Split(dic(dkey), "|")(0)
sh.Cells(xRow, "C").Value = Split(dic(dkey), "|")(1)
xRow = xRow + 1
Next dkey
sh.Columns("A:C").AutoFit
End Sub
test:
I wrote code for you to do this job. Please install it in a standard code module. That is one that you have to insert. None of the existing is suitable.
Option Explicit
Enum Nws ' Worksheet setup (set values as required)
NwsFirstDataRow = 2
NwsNumColumns = 8 ' total number of columns in the sheet
NwsID = 1 ' Columns: 1 = column A
NwsDesc ' undefined = previous + 1
NwsAmt = 5 ' 5 = column E
End Enum
Sub MergeRows()
' Variatus #STO 24 Jan 2020
Dim Wb As Workbook
Dim Ws As Worksheet
Dim Rng As Range
Dim RowArr As Variant
Dim Desc As String, Amt As Double
Dim Tmp As Variant
Dim R As Long
' define workbook and worksheet as required
Set Wb = ActiveWorkbook ' this need not be ThisWorkbook
Set Ws = Wb.Worksheets("Invoice") ' change as appropriate
Application.ScreenUpdating = False
With Ws
R = .Cells(.Rows.Count, NwsDesc).End(xlUp).Row
For R = R To NwsFirstDataRow Step -1
If (R Mod 25) = 3 Then 'NwsFirstDataRow Then
Application.StatusBar = "Another " & R & " rows to process."
End If
Tmp = Trim(.Cells(R, NwsID).Value)
If Len(Tmp) Then
Set Rng = Range(.Cells(R, 1), .Cells(R, NwsNumColumns))
RowArr = Rng.Value
RowArr(1, NwsAmt) = TextToAmount(RowArr(1, NwsAmt))
If Len(Desc) Then
' if you want a comma instead of a line break
' replace Chr(10) with "," in the next line:-
RowArr(1, NwsDesc) = RowArr(1, NwsDesc) & Chr(10) & Desc
RowArr(1, NwsAmt) = RowArr(1, NwsAmt) + Amt
Desc = ""
Amt = 0
End If
With Rng
.Value = RowArr
.Cells.VerticalAlignment = xlTop
.Cells(NwsAmt).NumberFormat = "$#,##0.00"
End With
.Rows(R).AutoFit
Else
Tmp = Trim(.Cells(R, NwsDesc).Value)
If Len(Desc) Then Desc = Chr(10) & Desc
Desc = Tmp & Desc
Tmp = TextToAmount(.Cells(R, NwsAmt).Value)
If Tmp Then Amt = Amt + Tmp
.Rows(R).EntireRow.Delete
End If
Next R
End With
With Application
.ScreenUpdating = True
.StatusBar = "Done"
End With
End Sub
Private Function TextToAmount(ByVal Amt As Variant) As Double
Dim Tmp As Variant
Tmp = Trim(Amt)
If Len(Tmp) Then Tmp = Mid(Tmp, InStr(Tmp, "$") + 1)
TextToAmount = Val(Tmp)
End Function
Before you can run it you need to set the enumerations at the top to tell the code where your data and columns are. Toward the same end, please set the variables for workbook (Wb) and worksheet (Ws) in the procedure itself.
Note that the code adds the price, if any, in the rows that are deleted to the amount set against the remaining item.
Finally, you will see that I programmed the different rows to become lines in a single cell. That isn't what you asked for. If you want the items separate by commas look for the remark in the code where you can change this.

How can I have my last array be printed and saved?

I have a script that maps out data and prints an array to a template based on when values in a column change (when the next set of duplicates start), basically stops and prints and array when cells M2<>M3 type deal.
It goes through and saves off a copy from the template for everyone but the final set of data, it just sits in the template and doesn't save off. How can I edit my code to go through all values and not leave the last set of data for me to manually save off?
Option Explicit
Sub Main()
Dim wb As Workbook
Dim Report_Data, Last, Login
Dim i As Long, j As Long, k As Long, a As Long
Dim Destination_Rng As Range
Workbooks.Open filename:="C:\Goal_Report_Template.xlsx"
Set wb = Workbooks("Goal_Report_Template.xlsx")
Set Destination_Rng = wb.Sheets("Sheet1").Range("A2")
With ThisWorkbook.Sheets("Q1 report")
Report_Data = .Range("W2", .Range("A" & Rows.Count).End(xlUp))
End With
wb.Activate
Application.ScreenUpdating = False
For i = 1 To UBound(Report_Data)
If Report_Data(i, 14) <> Last Then
If i > 1 Then
Destination_Rng.Select
wb.SaveCopyAs ThisWorkbook.Path & Application.PathSeparator & _
ValidFileName(Login & " - " & Last & " - Goal Reporting.xlsx")
End If
Rows(1).Offset(1, 0).Resize(Rows.Count - 1).EntireRow.ClearContents
Last = Report_Data(i, 14)
Login = Report_Data(i, 13)
j = 0
End If
a = 0
For k = 1 To UBound(Report_Data, 2)
Destination_Rng.Offset(j, a) = Report_Data(i, k)
a = a + 1
Next
j = j + 1
Next
End Sub
You need to perform another SaveAs after exiting the i loop. You can avoid duplicating code by breaking that out into a separate sub.
Untested:
Sub Main()
Dim wb As Workbook
Dim Report_Data, Last, Login, Current
Dim i As Long, j As Long, k As Long, a As Long
Dim Destination_Rng As Range
Set wb = Workbooks.Open(Filename:="C:\Goal_Report_Template.xlsx")
Set Destination_Rng = wb.Sheets("Sheet1").Range("A2")
With ThisWorkbook.Sheets("Q1 report")
Report_Data = .Range("W2", .Range("A" & .Rows.Count).End(xlUp))
End With
Application.ScreenUpdating = False
For i = 1 To UBound(Report_Data)
Current = Report_Data(i, 14)
If Current <> Last Then
If i > 1 Then SaveCopy wb, Login, Last '<< save this one
Destination_Rng.CurrentRegion.Offset(1, 0).ClearContents
Login = Report_Data(i, 13)
j = 0
Else
j = j + 1
End If
For k = 1 To UBound(Report_Data, 2)
Destination_Rng.Offset(j, k - 1) = Report_Data(i, k)
Next k
Next i
SaveCopy wb, Login, Last '<< save the last report
End Sub
Sub SaveCopy(wb As Workbook, Login, Last)
wb.SaveCopyAs ThisWorkbook.Path & Application.PathSeparator & _
ValidFileName(Login & " - " & Last & " - Goal Reporting.xlsx")
End Sub

How to set an automatically generated Option Button to 'True' based on the value in another range in VBA?

I generated radio buttons with the help of the answer to How to set an automatically generated radio button to true in VBA?.
My requirement is to set the automatically generated Option button to 'True' when there is a value x in another sheet.
Figure 1: The source to check the value.
Figure 2: The sheet to which the Mark x should be reflected as True.
The radio buttons that are generated are as Indexed as OB2_2 for the option button in 2 row and 2 column.
Here is the code
Private Sub AddOptionButtons(ByRef TargetRange As Range)
Dim m As Variant
m = Sheets("ALLO").Range("D23").Value + 1
Sheets("Final").Range("A2:A" & m).Copy Destination:=Sheets("Int_Result").Range("A2:A" & m)
Dim oCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top
Next
Call OB2_Click(oCell)
End Sub
Sub OB2_Click(oCell)
Dim col, ro, m As Variant
Dim Shap As Shape
m = Sheets("ALLO").Range("D23").Value + 1
For Each Shap In Sheets("Int_Result").Shapes
For ro = 2 To m Step 1
For col = 1 To 13 Step 1
If Sheets("Final").Cells(ro, col).Value = "" Then
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
Else
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = True
End If
Next col
Next ro
Next Shap
End Sub
I get
"Object variable or With block variable not set" or "Wrong number of arguments or Invalid Property assignment".
on this line
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
How do I access the automatically generated radio buttons?
You need to use
Sheets("Int_Result").OLEObjects("OB2_2").Object.Value = True
Set loop not for shapes, but normal to last row and last column.
So for example:
Dim oCell As Range
Dim LastCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.Row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top
Set LastCell = oCell
Next
Call OB2_Click(LastCell)
Sub OB2_Click(oCell as Range)
Dim col As Long, ro As Long
dim m as long, k as long
col = oCell.Column
ro = oCell.Row
For m = 2 to ro
For k = 2 to col
If Sheets("Final").Cells(m, k).Value = "" Then
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = False
Else
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = True
End If
Next k
Next m
End sub

VBA Runtime Error 9 when checking whether String has two parts

I am working with cells in a column, which have to be split. Element 1 of the string is supposed to be posted separately from Element 2 of the same string, each on another Worksheet.
String "123 ABC" -> "123" in column C and "ABC" in column D
I am running into a Runtime-Error 9 "Index out of Range" if one of the cells I am checking only contains "123" or "ABC" but no both parts.
I tried to work around it in the way you see in my code below. Needless to say it does not work.
Could one of the more experienced Excel-Gurus help me out here?
Thank you in advance for your time!
Application.ScreenUpdating = False
Dim wbInput As Workbook, wbOutput As Workbook
Set wbOutput = ActiveWorkbook
Dim wsInput As Worksheet, wsOutput As Worksheet, wsMistakes As Worksheet
Set wsOutput = wbOutput.Worksheets("FehlerVorkommen")
Set wsMistakes = wbOutput.Worksheets("NichtZuweisbar")
Dim lRowInput As Long, lRowOutput As Long, lRowMistakes As Long
Dim Lieferant As Range
Dim InputFile As String, myElements() As String
lRowOutput = wsOutput.Range("A" & Rows.Count).End(xlUp).Row
wsOutput.Range("A2:G" & lRowOutput).Clear
wsMistakes.Range("A2:G500").Clear
InputFile = Application.GetOpenFilename()
If InputFile = "Falsch" Then
Exit Sub
End If
Set wbInput = Workbooks.Open(InputFile)
Set wsInput = wbInput.Worksheets("owssvr")
lRowInput = wsInput.Range("A" & Rows.Count).End(xlUp).Row
'Get all Information
For Each Lieferant In wsInput.Columns(1).Rows("2:" & lRowInput)
If wsInput.Columns(3).Rows(Lieferant.Row) <> vbNullString Then
myElements = Split(wsInput.Columns(3).Rows(Lieferant.Row).Value, " ", 2) 'A maximum of 2 String-Parts to avoid 4-5 splits whenever there is a GmbH or AG or whatever
If IsEmpty(myElements(1)) = True Then <<<<<<<<<ERROR HERE<<<<<<<<<<<
lRowMistakes = wsMistakes.Range("A" & Rows.Count).End(xlUp).Row
NextRow = lRowMistakes + 1
wsInput.Columns(1).Rows(Lieferant.Row).Copy Destination:=wsMistakes.Columns(1).Rows(NextRow)
NextRow = NextRow + 1
Else
If IsNumeric(wsInput.Columns(1).Rows(Lieferant.Row)) = True And wsInput.Columns(1).Rows(Lieferant.Row) <> vbNullString _
And IsNumeric(wsInput.Columns(2).Rows(Lieferant.Row)) = True And wsInput.Columns(2).Rows(Lieferant.Row) <> vbNullString Then
wsInput.Columns(1).Rows("2:" & lRowInput).Copy Destination:=wsOutput.Columns(1).Rows("2:" & lRowInput) 'Task Namen
wsInput.Columns(2).Rows("2:" & lRowInput).Copy Destination:=wsOutput.Columns(2).Rows("2:" & lRowInput) 'Bestellpositionen
wsOutput.Columns(3).Rows(Lieferant.Row).Value = myElements(0) 'ID
wsOutput.Columns(4).Rows(Lieferant.Row).Value = myElements(1) 'Name
wsInput.Columns(3).Rows("2:" & lRowInput).Copy Destination:=wsOutput.Columns(5).Rows("2:" & lRowInput) 'Fehlerarten
Else 'Get all wrong inputs on separate Sheet
lRowMistakes = wsMistakes.Range("A" & Rows.Count).End(xlUp).Row
NextRow = lRowMistakes + 1
wsInput.Columns(1).Rows(Lieferant.Row).Copy Destination:=wsMistakes.Columns(1).Rows(NextRow)
NextRow = NextRow + 1
End If
End If
Else 'Get all wrong input on separate Sheet
lRowMistakes = wsMistakes.Range("A" & Rows.Count).End(xlUp).Row
NextRow = lRowMistakes + 1
wsInput.Columns(1).Rows(Lieferant.Row).Copy Destination:=wsMistakes.Columns(1).Rows(NextRow)
NextRow = NextRow + 1
End If
Next Lieferant
wbInput.Close
This line doesn't do what you think it's doing:
If IsEmpty(myElements(1)) = True
First, specifying a limit for the Split function doesn't mean that you always get that many elements in the array. Second, IsEmpty tests to see if a Variant is type VT_EMPTY, not whether a String has a value (Split returns a strongly typed array).
Just test the UBound instead:
If UBound(myElements) > 0 Then

VBA Coding to pull data

I have 50 .xls files saved on a shared drive by the name of users. Eg: "Rahul Goswami.xls", "Rohit Sharma.xls", etc.
Each Excel file contains 2 worksheets: "Case Tracker" and "Pending Tracker".
In the "Case Tracker" worksheet users put their daily data/ daily production.
I wanted VBA code to pull the entire "Case Tracker" worksheet from all 50 Excel files in one separate Excel workbook, one below the other.
Currently I am copy-pasting the data from the Excel files to the master workbook to "Sheet1".
Can there be something where I put the date and the data will come automatically for that date from all the 50 files?
Column A to J contains the data provided below. This example is given for 1 user.
Date Advisor Userid BP URN Stage Case Type Previous Status Current status Category
10-Apr Rahul Goswami goswami 123456 98765431 1 URN New Pend abc
Sub Beachson()
Dim z As Long, e As Long, d As Long, G As Long, h As Long Dim f As String
d = 2
Cells(1, 1) = "=cell(""filename"")"
Cells(1, 2) = "=left(A1,find(""["",A1)-1)"
Cells(2, 1).Select
f = Dir(Cells(1, 2) & "*.xls")
Do While Len(f) > 0
## Heading ##
ActiveCell.Formula = f
ActiveCell.Offset(1, 0).Select
f = Dir()
Loop
z = Cells(Rows.Count, 1).End(xlUp).Row
For e = 2 To z
If Cells(e, 1) <> ActiveWorkbook.Name Then
Cells(d, 2) = Cells(e, 1)
Cells(1, 4) = "=Counta('" & Cells(1, 2) & "[" & Cells(e, 1) & "]Case Tracker'!I:I)"
For h = 10 To Cells(1, 4)
For G = 1 To 10
Cells(1, 3) = "='" & Cells(1, 2) & "[" & Cells(e, 1) & "]Case Tracker'!" & Chr(G + 64) & h
Cells(d, G + 2) = Cells(1, 3)
Next G
d = d + 1
Next h
End If
d = d + 1
Next e
MsgBox "collating is complete."
End Sub
I would avoid storing information in sheet, then going to VBA, then again to sheet, etc.
As for your problem of not being able to pull data when a file is open, I would suggest creating another instance of Excel.Application and opening files from it in ReadOnly mode.
This is the code which worked for me (the ability to find particular dates is also implemented):
Sub Beachson2()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
Dim App As Object
Set App = CreateObject("Excel.Application")
Dim wsSource As Worksheet
Dim sFold As String
sFold = ThisWorkbook.Path & "\"
Dim sFile As String
Dim i As Long, j As Long
Dim cell As Range
' Setting date
Dim sInput As String, dInput As Date
sInput = Application.InputBox("Enter A Date")
If IsDate(sInput) Then
dInput = DateValue(sInput)
Else
MsgBox "Invalid date. Exiting..."
Exit Sub
End If
Application.ScreenUpdating = False
' Pulling data
i = 1
sFile = Dir(sFold & "\*.xls")
Do While sFile <> ""
If sFile <> sFold & ThisWorkbook.Name Then
Set wsSource = App.Workbooks.Open(Filename:=sFold & sFile, ReadOnly:=True).Sheets("Case Tracker")
For Each cell In wsSource.Range("A1:A" & wsSource.UsedRange.Rows.Count)
If cell.Value = CStr(dInput) Then
With ws.Cells(Rows.Count, 1).End(xlUp)
If IsEmpty(.Value2) Then
.Value2 = sFile
ElseIf .Value2 <> sFile Then
.Offset(1).Value2 = sFile
Else
'do nothing
End If
End With
If ws.Cells(Rows.Count, 2).End(xlUp).Value2 <> sFile Then
ws.Cells(i, 2).Value2 = sFile
End If
For j = 3 To 12
ws.Cells(i, j).Value = wsSource.Cells(cell.Row, j - 2).Value
Next
i = i + 1
End If
Next
wsSource.Parent.Close
End If
sFile = Dir()
Loop
Application.ScreenUpdating = True
App.Quit
MsgBox "collating is complete."
Set App = Nothing
End Sub
The code is stored in the master file.
Even in the code there is no one specific Date format defined, but I still think it is capable of causing problems. If you find problems regarding date formats, please post your used date format.

Resources