Sub combinedata()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim rng As Range, lrow As Long
Dim r As Range, lr As Long, cell As Range
Dim ws As Worksheet, ws1 As Worksheet
Dim r1 As Range
Set ws = ActiveSheet
lrow = ws.Cells(Cells.Rows.Count, "w").End(xlUp).Row
lr = ws.Cells(Cells.Rows.Count, "x").End(xlUp).Row
Set rng = ws.Range("W4:W" & lrow)
Set r = ws.Range("x4:x" & lr)
Sheets.Add After:=Sheets(Sheets.Count)
Set ws1 = ActiveSheet
rng.Copy ws1.Range("A1")
r.Copy ws1.Range("B1")
lrow = ws1.Cells(Cells.Rows.Count, "a").End(xlUp).Row
lr = ws1.Cells(Cells.Rows.Count, "b").End(xlUp).Row
Set rng = ws1.Range("A1:A" & lrow)
Set r = ws1.Range("B1:B" & lr)
For Each cell In r
If Trim(cell.Value) <> "" Then
Set r1 = rng.Find(What:=cell.Value, After:=Cells(1, 1), LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, SearchFormat:=False)
If r1.Offset(0, 2).Value = "" Then
r1.Offset(0, 2).Value = cell.Value
Else
r1.Offset(0, 2).Value = r1.Offset(0, 2).Value & "," & cell.Value
End If
If Application.WorksheetFunction.CountIf(r, cell.Value) > 1 Then r1.Offset(0, 3).Value = r1.Offset(0, 3).Value + 1
Set r1 = Nothing
End If
Next cell
ws1.Columns("B:B").Delete
lrow = ws1.Cells(Cells.Rows.Count, "a").End(xlUp).Row
ws1.Range("A1:C" & lrow).Copy ws.Range("W4")
ws1.Delete
ws.Cells.EntireColumn.AutoFit
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Sub combinedata()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim rng As Range, lrow As Long
Dim r As Range, lr As Long, cell As Range
Dim ws As Worksheet, ws1 As Worksheet
Dim r1 As Range
Set ws = ActiveSheet
lrow = ws.Cells(Cells.Rows.Count, "w").End(xlUp).Row
lr = ws.Cells(Cells.Rows.Count, "x").End(xlUp).Row
Set rng = ws.Range("W4:W" & lrow)
Set r = ws.Range("x4:x" & lr)
For Each cell In r
If Trim(cell.Value) <> "" Then
Set r1 = rng.Find(What:=cell.Value, After:=Cells(4, 23), LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, SearchFormat:=False)
If r1.Offset(0, 3).Value = "" Then
r1.Offset(0, 3).Value = cell.Value
Else
r1.Offset(0, 3).Value = r1.Offset(0, 3).Value & "," & cell.Value
End If
If Application.WorksheetFunction.CountIf(r, cell.Value) > 1 Then r1.Offset(0, 4).Value = r1.Offset(0, 4).Value + 1
Set r1 = Nothing
End If
Next cell
ws.Cells.EntireColumn.AutoFit
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Open in new window
Saurabh....