Results 1 to 7 of 7

Thread: [RESOLVED] Corect runtime error in matching columns

  1. #1

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    Resolved [RESOLVED] Corect runtime error in matching columns

    Hello guys I have got following code,

    the code check column A and B in sheet1 then match them with sheet2 A and B,


    Sheet1
    Name:  XiPnDCY.jpg
Views: 293
Size:  8.9 KB


    Sheet2
    Name:  xP4x4FM.jpg
Views: 318
Size:  7.4 KB

    if column A and B sheet1 match column a and B in sheet2,
    take the matching cell in this result,
    sheet 1 same row column J the value * the value in column G same row sheet2,

    but if there are cells in sheet1 and column A and B that not exists in Sheet2,

    I get this error

    Runtime error 13 : incompatible types




    See attached file.Compare_cells.zip

    Could someone help me ?

    Thank you in advance
    Last edited by elmnas; Aug 3rd, 2015 at 10:08 AM.

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Corect runtime error in matching columns

    what's your code to do the matching?

  3. #3

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    Re: Corect runtime error in matching columns

    Quote Originally Posted by vbfbryce View Post
    what's your code to do the matching?
    sorry my mistake,

    see attachment

  4. #4
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Corect runtime error in matching columns

    I don't get any errors when I run your code as is. However, you should change this:

    Code:
    Set ws1 = ActiveSheet
    to this:

    Code:
    Set ws1 = Worksheets("sheet1")
    in case Sheet2 is active when you run the code. Making that change did not yield any errors, either.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Corect runtime error in matching columns

    while the code ran without error i am not sure it would matching correctly, a single run matches the following rows
    1 1
    1 6
    6 1
    6 6

    though mystring always gets its value from sheet2 at the current row in sheet1, which is probably not the desired result

    as you have already set worksheet objects, you should avoid going back to the individual sheets, just work with the objects
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Corect runtime error in matching columns

    Most likely, when you thought that you deleted a value, you typed a " " instead of hitting the delete key. This is the peril of freely treating text and numbers as the same thing. If you must, then at least perform a IsNumeric(var) check before performing any numeric computations with the value.

  7. #7

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    Re: Corect runtime error in matching columns

    Sdak
    Attached Files Attached Files
    Last edited by elmnas; Aug 4th, 2015 at 02:38 AM.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width