Sub aaa()
Lastcol = ActiveSheet.UsedRange.Columns.Count
Lastrow = ActiveSheet.UsedRange.Rows.Count
cola = Lastcol + 2
colb = Lastcol + 3
colc = Lastcol + 4
Cells(1, cola) = "A"
Cells(1, colb) = "B"
Cells(1, colc) = "C"
For r = 2 To Lastrow
For c = 2 To Lastcol
ColumnLetter = Cells(1, c)
If Cells(r, c) = "A" Then sa = sa & ColumnLetter
If Cells(r, c) = "B" Then sb = sb & ColumnLetter
If Cells(r, c) = "C" Then sc = sc & ColumnLetter
Next
Cells(r, cola) = sa
Cells(r, colb) = sb
Cells(r, colc) = sc
sa = "": sb = "": sc = ""
Next
End Sub |