+ Reply to Thread
Results 1 to 8 of 8

Run time error - type mismatch

  1. #1
    Registered User
    Join Date
    01-04-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    20

    Run time error - type mismatch

    Hi

    Can anyone help to solve my problem? I have attached a sample file for you to easy reference. So when the code run until the loop function, it will prompt an error message.

    The idea is to open the selected file and the copy the data from the selected to this master file by searching the column A. Column A has the identical text in all the files that are to be copied from.

    Thank you

    Regards,
    Justin
    Attached Files Attached Files
    Last edited by justinng; 08-10-2009 at 11:27 PM.

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Run time error - type mismatch

    Which line is highlighted when the code errors?

    I'm presuming that the file you uploaded is just an example file, as none of the sheets have the names that the macro expects?
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  3. #3
    Registered User
    Join Date
    01-04-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Run time error - type mismatch

    Hi Phil,

    Thanks for replying. Yes, it is an example file. The error appeared when the code run into

    For Each rngCell In rngDataR
    Set rngFound = wsOpenR.Columns(1).Find(what:=CLng(wsDataR.Cells(rngCell.Row, 1).Value))

    Thank you very much for your help.

    Best Regards,
    Justin

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Run time error - type mismatch

    What Error message did you get?

    Your code is written specifically to present an error message if there are ANY problems.

    I would guess that either rngDataR has ended up not being set to anything, or that on that line of code the what was not found in wsOpenR.Columns(1).

    The error message would be useful to know though.

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Run time error - type mismatch

    I'd guess the CLng is failing here:
    Please Login or Register  to view this content.
    What value is in the cell when the code fails?
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    01-04-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Run time error - type mismatch

    Hi,

    I have an error number #13.

    The field that they are trying to search is a text. like "ABC", "CBA" as indicate in my test file. I need the code to search, match the column with the same text and return the value under the respective company.

    Thanks
    Justin

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Run time error - type mismatch

    You can't convert "ABC" to a long integer so you need to remove the CLng function:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-04-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Run time error - type mismatch

    Dear Romperstomper,

    Thank you very much for the help, it has been a great help to me. It is working now.

    Justin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1