arnabmit
New Member
- Joined
- Mar 28, 2009
- Messages
- 27
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hi,
Am an amateur in VBA. I need a Macro which will collate value of cells (not formulas) from specific cells in each excel files in a folder, and then collate them in a separate excel file.
I have put together a code from bits and pieces from my earlier practice projects, however, as expected, it's not working.

Please help!!!
Am an amateur in VBA. I need a Macro which will collate value of cells (not formulas) from specific cells in each excel files in a folder, and then collate them in a separate excel file.
I have put together a code from bits and pieces from my earlier practice projects, however, as expected, it's not working.


Please help!!!

Code:
Dim myStrings As Variant
Dim TotalExpectedValues As Long
Dim MyMPath As String
Dim myMFiles() As String
Dim MyMFile As String
Dim fCtr As Long
Dim oRow As Long
Dim fso, txtFile
Dim wb As Workbooks
Dim wks As Worksheet
Dim iCtr As Long
Sub PMSCollate()
MyMPath = Worksheets(1).TextBox1.Text
If Right(MyMPath, 1) <> "\" Then
MyMPath = MyMPath & "\"
End If
On Error Resume Next
MyMFile = Dir(MyMPath & "*.xls")
On Error GoTo 0
If MyMFile = "" Then
MsgBox "No Excel files in this Folder"
Exit Sub
End If
TotalExpectedValues = 7
fCtr = 0
Set wks = Workbooks.Add(1).Worksheets(1)
wks.Range("a1").Resize(1, TotalExpectedValues).Value = Array("Name", "SAP ID", "Designation", "Supervisor", "Band", "Department", "Score")
Do While MyMFile <> ""
On Error Resume Next
fCtr = fCtr + 1
With wks
oRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
ReDim Preserve myMFiles(1 To fCtr)
myMFiles(fCtr) = MyMFile
Application.ScreenUpdating = False
Set wb = Workbooks.Open(myMFiles(fCtr), True, True)
Sheets("Appraisal Form 2012").Select
myStrings = Array(Range("D4").Value, Range("D5").Value, Range("D6").Value, Range("D7").Value, Range("G5").Value, Range("G6").Value, Range("D33").Value)
MsgBox myStrings
For iCtr = LBound(myStrings) To UBound(myStrings)
wks.Cells(oRow, "A").Offset(0, iCtr).Value = myStrings
Next iCtr
MyMFile = Dir()
On Error GoTo 0
Loop
wks.UsedRange.Columns.AutoFit
Range("A1:G1").Select
Selection.Font.Bold = True
Columns("A:G").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A1").Select
End Sub