PDA

View Full Version : File (path to a folder) not found



Cezar
02-04-2011, 01:58 AM
Hi

I will just start by letting you all know I am very new to VBA still counting in weeks :whistle:But better late than never right....

How ever to the problem. I have :banghead: with this code I have been asked to look at.

I get an "run-time error '13'
Type mismatch"


Function selectAnCopyLines(dat, fic)
j = firstFreeLine()
For j = 2 To 320000
If CStr(Workbooks(fic).Sheets(1).Cells(j, 7)) = CStr(dat) Then 'Compares the dates entered and the one in column H of Team stats
Workbooks("Teamstats.xlsx").Sheets(3).Cells(j, 1) = 1
Workbooks("Teamstats.xlsx").Sheets(3).Cells(j, 2) = Format(Now, "mmmm")
Workbooks("Teamstats.xlsx").Sheets(3).Cells(j, 3) = DatePart("ww", Now, vbMonday, vbFirstFourDays)
For k = 4 To 19
Workbooks("Team stats.xlsx").Sheets(3).Cells(j, k) = Workbooks(fic).Sheets(1).Cells(i, k + 1)
'Workbooks("Team stats test.xlsx").Sheets(3).Range(Cells(j, 4), Cells(j, 15)) = Workbooks(fic).Sheets(1).Range(Cells(i, 5), Cells(i, 16)) doesn't work!!
Next
j = j + 1
End If
Next
Workbooks(fic).Close savechanges:=False
End Function


in that code the debuger show that this line is the problem line:
If CStr(Workbooks(fic).Sheets(1).Cells(j, 7)) = CStr(dat) Then
can any one see what went wrong?

Please if you can try to explain to me also why it went wrong so I can learn for next time :think:

Thanks in advance

Jesper

Kenneth Hobs
02-04-2011, 06:45 AM
Examine fic to be sure that the workbook named fic is actually open.

I would use a Sub rather than a Function. Your function is not returning any value.

When updating cell values, you should turn off screen updating and calculation.

In the date comparison, why convert to string?

You should define the input parameter types. e.g.
Sub selectAnCopyLines(dat as Date, fic as String)