MikeGozna
New Member
- Joined
- Feb 19, 2019
- Messages
- 10
- Platform
- Windows
Hi Guys, hope you can help with this.
I have code which opens every file in 6no different directories and looks for the phrase "In progress" on sheet "Summary" in every file.
If it finds the string "In Progress" it counts the file and carry's on to the next file. When the whole loop is finished it places a list of all the files from the 6 directories in my main workbook on Sheet 1
starting at A50, B50, C50, D50, E50, F50. All is fine up to this point. But column A is perfect and starts at A50 as required, but subsequent columns, say B, which should start at B50 always starts 1 row below the
previous column, and so it goes on with each of the columns stating 1 row below the previous column end row. Please could someone give me a simple workaround for this please. I am not the good with VBA, so an explanation of why this occurs would be much appreciated. Thank you in advance.
Below is the code for one loop through one of the directories,
If there are better ways to do this (and im sure there are),please advise, but if you could explain, again i would be grateful.
I have code which opens every file in 6no different directories and looks for the phrase "In progress" on sheet "Summary" in every file.
If it finds the string "In Progress" it counts the file and carry's on to the next file. When the whole loop is finished it places a list of all the files from the 6 directories in my main workbook on Sheet 1
starting at A50, B50, C50, D50, E50, F50. All is fine up to this point. But column A is perfect and starts at A50 as required, but subsequent columns, say B, which should start at B50 always starts 1 row below the
previous column, and so it goes on with each of the columns stating 1 row below the previous column end row. Please could someone give me a simple workaround for this please. I am not the good with VBA, so an explanation of why this occurs would be much appreciated. Thank you in advance.
Below is the code for one loop through one of the directories,
If there are better ways to do this (and im sure there are),please advise, but if you could explain, again i would be grateful.
VBA Code:
Private Sub CommandButton4_Click()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Works out D M Ws DAYWORKS Cost and profit Figures
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
Range("I6:I10,M6:M10,Q6:Q10,M17:M21,Q17:Q21").ClearContents
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim totalValue4 As Integer
Dim totalValue44 As Integer
Dim i As Integer
Application.ScreenUpdating = False
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("C:\New Dashboard\Jobcosting\DMW\Dayworks")
'loops through each file in the directory
For Each objFile In objFolder.Files
'Debug.Print objFile.Path
Set Wb = Workbooks.Open(objFile.Path)
If Worksheets("Summary").ComboBox1.Value = "In Progress" Then
Cells(i + 50, 1) = objFile.name
i = i + 1
totalValue4 = totalValue4 + Wb.Worksheets("Lists").Range("M5")
totalValue44 = totalValue44 + Wb.Worksheets("Lists").Range("M7")
End If
Wb.Close SaveChanges:=False
Next objFile
ActiveWorkbook.Worksheets("Sheet1").Range("M17") = totalValue4
ActiveWorkbook.Worksheets("Sheet1").Range("Q17") = totalValue44
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Works out GOZNA DAYWORKS Cost and profit Figures
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim totalValue5 As Integer
Dim totalValue55 As Integer
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("C:\New Dashboard\Jobcosting\Gozna\Dayworks")
'loops through each file in the directory
For Each objFile In objFolder.Files
'Debug.Print objFile.Path
Set Wb = Workbooks.Open(objFile.Path)
If Worksheets("Summary").ComboBox1.Value = "In Progress" Then
Cells(i + 50, 2) = objFile.name
i = i + 1
Application.CutCopyMode = False
totalValue5 = totalValue5 + Wb.Worksheets("Lists").Range("M5")
totalValue55 = totalValue55 + Wb.Worksheets("Lists").Range("M7")
End If
Wb.Close SaveChanges:=False
Next objFile
ActiveWorkbook.Worksheets("Sheet1").Range("M19") = totalValue5
ActiveWorkbook.Worksheets("Sheet1").Range("Q19") = totalValue55