Hi
I have this bit of code which does multiple things, it opens a two files and pastes data from one to other and then adds th values to a sheet in that workbook. It then should loop through a folder and copy the data range A2:M14 and paste it into the template workbook on the identified sheet in the cell B2 and then close the file and open the next and paste the data range under the data there but also leaving a white line between them.
However currently it wont loop as it pulls an error at the highlighted line below and also does not copy and paste the correct data.
Option Explicit
Sub AverageGraph()
Dim i As String
Dim l As String
Dim wbCsv As Workbook
Dim wsMyCsvSheet As Worksheet
Dim lNextrow As Long
i = Range("B7").Value
l = Range("B8").Value
Application.Workbooks.Open "C:\Documents and Settings\SeymourJ\Desktop\Book1Template.xlsx"
Application.Workbooks.Open "C:\Documents and Settings\SeymourJ\Desktop\Actual_Participation_02_2011.xls"
Workbooks("Actual_Participation_02_2011.xls").Sheets(1).Range("A2:A1000").Copy Destination:=Workbooks("Book1Template.xlsx").Sheets("Graphing").Range("B3")
Workbooks("Actual_Participation_02_2011.xls").Close
ActiveWorkbook.Sheets("Settings").Select
Range("B6").Value = i
Range("B7").Value = l
strFldr = "C:\Documents and Settings\SeymourJ\My Documents\Tasks\"
strFile = Dir(strFldr & "Graphing_MTH_Actual_Curr_Year" & "_*.csv")
Application.Calculation = xlCalculationManual
lNextrow = 1
If Len(strFile) > 0 Then
Do
Set wbCsv = Workbooks.Open(Filename:=strFldr & "\" & strFile)
Set wsMyCsvSheet = wbCsv.Sheets(1)
With Workbooks("Book1Template.xlsx").Sheets("MTH")
.Cells(lNextrow, 2) = WorksheetFunction.CountA(wsMyCsvSheet.Range("A2:M14"))
End With
lNextrow = lNextrow + 1
'close it
wbCsv.Close
'go to next file
strFile = Dir
Application.StatusBar = strFile
Loop Until Len(strFile) = 0
End If
End Sub
Can anyone work out why it is not running?
Thanks
Jeskit
Bookmarks