Hi,
In the attached workbook , Sheet1 has the raw data where as sheet2 has the result which I want to have with help of macros.
Macro to combine rows with common data and delete duplicates
-
-
Re: Macro to combine rows with common data and delete duplicates
This should do
Code
Display MoreSub test() Dim a, i As Long, ii As Long, w a = Sheets("sheet1").Cells(1).CurrentRegion.Value With CreateObject("Scripting.Dictionary") For i = 1 To UBound(a, 1) If Not .exists(a(i, 1)) Then ReDim w(1 To UBound(a, 2)): .Item(a(i, 1)) = w Else w = .Item(a(i, 1)) End If For ii = 1 To UBound(a, 2) If a(i, ii) <> "" Then w(ii) = a(i, ii) Next .Item(a(i, 1)) = w Next w = Application.Index(.items, 0, 0) End With With Sheets("sheet2").Cells(1).Resize(UBound(w, 1), UBound(w, 2)) .CurrentRegion.ClearContents .Value = w End With End Sub
-
Re: Macro to combine rows with common data and delete duplicates
Hi
It works fine can we have macro to work on 19 digits since the results in column A shows 8.94426E+18 -
-
Re: Macro to combine rows with common data and delete duplicates
thanks a lot
-
-
Re: Macro to combine rows with common data and delete duplicates
Hi
Could you please help me, the macro doesn't work if the record count exceeds 1 lakh. -
Re: Macro to combine rows with common data and delete duplicates
I am getting type mismatch error on below.
w = Application.Index(.items, 0, 0)
-
Re: Macro to combine rows with common data and delete duplicates
Try change to
Code
Display MoreSub test() Dim a, i As Long, ii As Long, w a = Sheets("sheet1").Cells(1).CurrentRegion.Value With CreateObject("Scripting.Dictionary") For i = 2 To UBound(a, 1) If Not .exists(a(i, 1)) Then .Item(a(i, 1)) = .Count + 2 For ii = 1 To UBound(a, 2) a(.Count + 1, ii) = a(i, ii) Next Else For ii = 1 To UBound(a, 2) If a(i, ii) <> "" Then a(.Item(a(i, 1)), ii) = a(i, ii) Next End If Next i = .Count + 1 End With With Sheets("sheet2").Cells(1).Resize(i, UBound(a, 2)) .CurrentRegion.ClearContents .Columns(1).NumberFormat = "@" .Value = a End With End Sub
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!