+ Reply to Thread
Results 1 to 1 of 1

Run-Time Error 13 'Type Mismatch'

Hybrid View

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2003
    Posts
    1

    Run-Time Error 13 'Type Mismatch'

    Hi everyone, I am new to the forum and to excel VB.
    Recently I used one macro from this forum, but I keep on getting the Run-Time Error 13 'Type Mismatch'
    Below is the macro code I used. I got the error on the red line.

    Please help me.

    __________________________
    Sub MergeData()
    
      Dim C As Long
      Dim Data As Variant
      Dim Dict As Object
      Dim Key As Variant
      Dim R As Long
      Dim Rng As Range
      Dim RngEnd As Range
      Dim Wks As Worksheet
      
        Set Wks = Worksheets("Sheet1")
        
        Set Rng = Wks.Range("A1", Wks.Cells(1, Columns.Count).End(xlToLeft)).Offset(1, 0)
        Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
        Set Rng = Wks.Range(Rng, RngEnd)
        
        Set Dict = CreateObject("Scripting.Dictionary")
        Dict.CompareMode = vbTextCompare
        
        
          For Each Cell In Rng.Columns(1).Cells
             Key = Trim(Cell.Offset(0, 1)) & Trim(Cell.Offset(0, 2))
            If Not Dict.Exists(Key) Then
               ReDim Data(Rng.Columns.Count - 1)
                 Data(0) = Cell                  'SR Number
                 Data(1) = Cell.Offset(0, 1)     'SupplierName
                 Data(2) = Cell.Offset(0, 2)     'POTitle
               For C = 3 To Rng.Columns.Count - 1
                 Data(C) = Cell.Offset(0, C)
               Next C
               Dict.Add Key, Data
            Else
               Data = Dict(Key)
                 For C = 3 To Rng.Columns.Count - 1
                   Data(C) = Data(C) + Cell.Offset(0, C)
                 Next C
               Dict(Key) = Data
            End If
          Next Cell
          
          Application.ScreenUpdating = False
          
            Rng.ClearContents
          
            For Each Key In Dict.Keys
              R = R + 1
              Rng.Rows(R).Value = Dict(Key)
            Next Key
          
          Application.ScreenUpdating = True
          
        Set Dict = Nothing
        
    End Sub
    ___________________________
    Last edited by Chintanpanchal; 08-29-2012 at 04:58 AM. Reason: Added code tags

+ 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