+ Reply to Thread
Results 1 to 33 of 33

[SOLVED TY] Type mismatch using array and DDL

  1. #1
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    [SOLVED TY] Type mismatch using array and DDL

    Hi, new here, pleased to meet you all.

    I have only v little experience with VB and have done the coding as below but keep getting a Type Mismatch error 13. It would be great if someone could tell me why this is happening and point me in the direction to correct it.

    The cells in XL sheet contain continuously updated DDLs (eg.=MT4|BID!EURUSD)
    TIA


    Please Login or Register  to view this content.
    Last edited by futurespec; 07-02-2012 at 09:45 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    Where does the error occur?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Error occurs at....

    In Private Sub Workbook_SheetCalculate(ByVal Sh As Object)

    at line:

    If (Sheet1.Cells(4, x).Value = PairVals(0, j)) Then

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    What is in the cell referred to in sheet1 when the code runs? Error value, text, other?

  5. #5
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    it is a value (continuously updated) with 5 decimal places

    No 'N/A' values are visible

    Have tried changing type to variant, string etc all to no avail... same error

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    I'd be willing to bet that it actually doesn't have a number value when the code is running as I can't see a reason for a Type Mismatch otherwise. If you use
    Please Login or Register  to view this content.
    does the error persist?

  7. #7
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Ok it stopped that mismatch but now the mismatch is at..

    Private Sub Workbook_Open()

    line...
    PairVals(0, j) = Sheet1.Cells(4, x).Value ' each link stored in array

    So does that give some idea for the error??

    Appreciate your help with this

  8. #8
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    No the error has returned still?


    Please Login or Register  to view this content.
    Back to same line
    ... If (Sheet1.Cells(4, x).Value = PairVals(0, j)) Then 'No change

  9. #9
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    This is hurting my head for something so simple (haha).
    Have attached stripped down spreadsheet if that helps.
    Attached Files Attached Files

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    Perhaps:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Ermm!!!
    No.
    Same error

    I need a swear box 'cos this is going to be something so obvious (or not as the case may be) :-(

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    Let's try and narrow it down then. If you change the Redim line to just:
    Please Login or Register  to view this content.
    do you still get the error? If so, where?

  13. #13
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Yes same error same place

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    OK, so it's not the conversion to a double that causes the problem. If you add this function in a normal module:
    Please Login or Register  to view this content.
    and then alter your code to:
    Please Login or Register  to view this content.
    does it resolve the issue?

  15. #15
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Do appreciate your ongoing help.

    No, it made no difference. (error in same place)

    Please bear in mind that I have very little clue as to what I am doing (that should be easy to accept).

    I am not convinced that it is the code. (like you say cannot see why it would be wrong).

    When I put the new code in the 'Off' button on my spreadsheet was selected but it keeps coming up with the error ... how would it do that if the macro should not be running??
    Does that make any sense or am I completely lost?

  16. #16
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    Where does the error occur with the new code?

    Edit: just noticed you said it is in the same place! Now I am stumped since the function should override any errors. In the VBEditor, under Tools - Options, on the General tab, what is the Error Checking option set to?
    Last edited by romperstomper; 07-02-2012 at 07:17 AM.

  17. #17
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Break on unhandled errors.

  18. #18
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    If GetValue(Sheet1.Cells(4, x)) = PairVals(0, j) Then 'No change

    Have also tried put a numeric value in the place of the link just to be sure. The array takes its' values from row 4 which is a copy of the link value anyway.

    So v strange and still no idea
    Last edited by futurespec; 07-02-2012 at 07:31 AM.

  19. #19
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    I'm stumped. The GetValue function should override any errors and just return 0 for that case so I can't see where a type mismatch occurs, and I can't replicate it in your workbook.
    You're not using x and j for anything else are you?

  20. #20
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    No, you have the full code.
    Kept it brief to try and isolate the problem.
    In some way I am pleased that it has stumped a 'guru' 'cos it has had me going around in ever decreasing circles and I do not like where I am ending up!

    Ignoring the code for a moment is there some weird setting in XL that might lead to this scenario?
    I have not knowingly changed anything but may well have done in the past.

    Is it possible to have more than 1 occurrence of the macro running concurrently? and if so how do I prevent that?

  21. #21
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    No it is not - VBA is single threaded, and I cannot think of any other setting that would allow this behaviour. Let's try and break down the offending line:
    Please Login or Register  to view this content.
    What message do you get if you use this version?

  22. #22
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    cell value .. correct
    array val... blank !

  23. #23
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    Did you Redim As Double?

  24. #24
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Yes
    As per one of your posts I think

  25. #25
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    Have you reopened the workbook? If the Open event hasn't run, then your 'array' is actually just an empty variant. If you don't have some other reason for redimensioning it, I would just use:
    Please Login or Register  to view this content.
    or use:
    Please Login or Register  to view this content.
    if you do need to redimension it on the fly.

  26. #26
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Have reopened now and no difference.
    Will not allow me to dimension the array in Public section

    Great problems trying to edit code ... when I hit the stop button the error message comes up and if I hit end the macro keeps kicking back in 'cos data is updated several times a second and I am unable to stop it unless ultra quick
    Last edited by futurespec; 07-02-2012 at 08:44 AM.

  27. #27
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    Move the declaration to a normal module rather than ThisWorkbook and then alter the GetValue function to:
    Please Login or Register  to view this content.

  28. #28
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    First the good news ... it has stopped throwing up the error message :-)

    Now the not so good news... it is not copying any of the data down to lower rows

  29. #29
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    OK, let's add some debugging:
    Please Login or Register  to view this content.
    what if anything can you see in the Immediate Window in the VBE? (Ctrl + G to open the Immediate Window if you don't already have it open)

  30. #30
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    Nothing under immediate (no I did not have it open)
    Under watch..
    Watch : : PairVals(0, 0) : <Out of context> : Variant/Empty : ThisWorkbook.Workbook_SheetCalculate

    Ok added that code....
    Now shows the correct value and it changing

  31. #31
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    If you had no data in row 5, then:
    Please Login or Register  to view this content.
    will give you the last row in the sheet. Try:
    Please Login or Register  to view this content.
    instead.

  32. #32
    Registered User
    Join Date
    07-02-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Type mismatch using array and DDL

    MAGIC!!!
    Big smiles, big thankyous; you are a star with such great patience. And yes you are a 'Guru'
    Really appreciated.

    Now could you please explain why I was getting the error in the first instance so that I do not do it again.

  33. #33
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Type mismatch using array and DDL

    I suspect your cells hadn't properly calculated when the sub was running (hence the error value check) but am not sure (and don't use DDE so can't verify that).

+ 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