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
___________________________
Bookmarks