Consulting

Results 1 to 2 of 2

Thread: File (path to a folder) not found

  1. #1
    VBAX Regular
    Joined
    Feb 2011
    Posts
    7
    Location

    Cool File (path to a folder) not found

    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

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.
    [VBA]Sub selectAnCopyLines(dat as Date, fic as String)[/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •