Consulting

Results 1 to 9 of 9

Thread: Transpose an array - type mismatch error

  1. #1
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    4
    Location

    Transpose an array - type mismatch error

    Hi All,

    i am not so great VBA as i am from C# background and stuck in this below issue from couple of days.

    i know this error occurs when a cell value is more than 255 characters , unfortunatly am not able to come over of it.

    can someone please help me to tweak this code. (error occurs at application .transpose)

    Dim DT
    ar = SWB.Sheets("Temp").Cells(1, 1).CurrentRegion.Value Set DT = CreateObject("Scripting.Dictionary") With DT .CompareMode = 1 ReDim v(1 To UBound(ar, 2)) For i = 2 To UBound(ar, 1) For n = 1 To UBound(ar, 2) str = str & Chr(2) & ar(i, n) v(n) = ar(i, n) Next If .exists(str) Then .Item(str) = Empty Else .Item(str) = v End If str = "" Next Dim nws As Worksheet Resultwb.Activate Set nws = Resultwb.Worksheets.Add(After:=Worksheets(Worksheets.Count)) For Each arr In .keys If IsEmpty(.Item(arr)) Then .Remove arr Next Var = .Items: j = .Count End With With nws.Range("a1").Resize(, UBound(ar, 2)) .CurrentRegion.ClearContents .Value = ar If j > 0 Then .Offset(1).Resize(j).Value = Application.Transpose(Application.Transpose(Var)) End If


  2. #2
    Can you provide some sample data which demonstrates the error?
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    4
    Location
    Hi Jan,

    thanks for the reply, am not sure how to put the data here, but you can test with any data just putting any cell value more than 255 character and code fails at application.transpose (type mismatch)

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,192
    Location
    My guess would be that var is either defined as string or has defaulted that way due to not being defined.

    Try defining var as Variant and see if this helps, if I remember correctly the max string length is 255 characters.

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  5. #5
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    4
    Location
    Hi Thanks for the reply and i have tried to say Var as variant but no help...

  6. #6
    If I add these declarations:
        Dim DT
        Dim ar As Variant
        Dim arr As Variant
        Dim var As Variant
        Dim j As Long
        Dim i As Long
        Dim n As Long
        Dim Str As String
    it runs without a hitch up to a length of 32767 characters in any cell.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  7. #7
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    4
    Location
    Hi problemm is transpose doesnt accept if any cell value is more than 255 char.

  8. #8
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,192
    Location
    Also why transpose twice in your original code?

    Application.Transpose(Application.Transpose(Var))
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  9. #9
    I have tested your code with my additions and it runs without errors for string lengths up to and including 32767 characters. SO the 255 character limit is not correct.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

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
  •