Hi

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

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

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

[VBA]
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
[/VBA]

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

Thanks in advance

Jesper