一行解決:
=B2&" "&TEXT(COUNTIFS($A$2:A$6, A2, $B$2:B$6, B2),"00")
VBA大法好:
Sub Macro1()
Set ws = ThisWorkbook.Worksheets("Sheet1") ' Change to the sheet you want to work with
lastRow = ws.Cells(ws.Rows.count, "A").End(xlUp).Row ' Find the last row with data in column A
For i = 2 To lastRow ' Loop through each row in the data
center = ws.Cells(i, "A").Value ' Get the center name
position = ws.Cells(i, "B").Value ' Get the position name
count = Application.WorksheetFunction.CountIfs(ws.Range("A2:A" & lastRow), center, ws.Range("B2:B" & lastRow), position) ' Count the number of occurrences of the center and position
ws.Cells(i, "C").Value = center & " " & position & " " & Format(count, "00") ' Output the center, position, and count
Next i
End Sub |