+ Reply to Thread
Results 1 to 10 of 10

Type Mismatch Error

  1. #1
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Talking Type Mismatch Error

    Hello,

    I am very new to VBA Programing and am still learning my way around things. I know that there is a Type Mismatch error on the Clocksum line but am not sure why. Any tips, pointers, or fixes would be greatly appreciated!

    Please Login or Register  to view this content.
    Last edited by Decoderman; 04-19-2011 at 12:27 PM.

  2. #2
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Type Mismatch Error

    Do you have some sample data that I can throw onto the sheet so that it doesn't fall out of the If loop? It runs right through for me without any data.
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

  3. #3
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Type Mismatch Error

    Yea no probelm. Sorry it wasn't posted with it before
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Type Mismatch Error

    What do you have in mind for this(code/worksheet) to do for you?
    Add up all of the hours for each clocknum, then highlight a row that meets the criteria in the loops?

    edit: clocksum = 0 but I think it is because the SUMPRODUCT(A2,F2,Q2,R2) isn't giving you what you want. Doing this manually you get a VALUE# error because R2 is the wrong type of data.
    Last edited by jwright650; 04-19-2011 at 01:04 PM.

  5. #5
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Type Mismatch Error

    The worker has a set number of hours that they should be working. If they work less than that I want to see if they assigned it to the correct Pay Code:

    4242 : 40 hrs
    4000: 32 hrs
    8005: 12 hrs

    In that order. The FF Man has a different set of hours.

    Does that clear anything up?


    If it isn't charged correctly I want the entire row highlighted.

    So yes. I believe what your saying is what I am trying to achieve.

  6. #6
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Type Mismatch Error

    clocksum = CLng([SumProduct((rclock = clocknum) * (rweek = weeknumber) * (rppe = ppe) * (rhrs))])


    Seems to work. No clue what clng is but it seems to atleast run without throwing out an error. Though it seems my statements arent being correctly stated.

  7. #7
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Type Mismatch Error

    The Clng allows the sumproduct to run without errors but it does not give the correct answer as to what the sumproduct should be. I checked it against the excel version of the formula and the excel version outputs 120 and the clng outputs 2029

  8. #8
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Type Mismatch Error

    re: =SUMPRODUCT(A2,F2,Q2,R2)

    R2 = "WK1" and is a string, so how does that work in the SUMPRODUCT formula?

  9. #9
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Type Mismatch Error

    Decoderman,

    I'm going through this thread trying to find what the issue is. At one point you were asked what the purpose of the macro is:

    Quote Originally Posted by Decoderman View Post
    The worker has a set number of hours that they should be working. If they work less than that I want to see if they assigned it to the correct Pay Code:

    4242 : 40 hrs
    4000: 32 hrs
    8005: 12 hrs

    In that order. The FF Man has a different set of hours.

    Does that clear anything up?

    If it isn't charged correctly I want the entire row highlighted.
    So I looked at the TestData you attached, and what I'm seeing is that you want the macro to do the following:
    • Check the total hours of each employee
    • If the total hours >40, the paycode should be 4242
    • If 40 > totalhours > 32, the paycode should be 4000
    • If 32 > totalhours > 12, the paycode should be 8005
    • If any of the paycodes are not correct, highlight the entire row

    With that information, I don't see that sumproduct is necessary at all. Here's the code I came up with to make that happen. Attached is a modified version of your TestData so you can see how it works.

    Please Login or Register  to view this content.



    Let me know if I have it wrong or the macro needs to do something else/more (I wasn't sure what you meant by "The FF Man has a different set of hours").

    Hope this helps,
    ~tigeravatar
    Attached Files Attached Files
    Last edited by tigeravatar; 04-20-2011 at 10:55 AM.

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: Type Mismatch Error

    I think this is what you were after originally:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

+ 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