Excel에서 일치하는 기준에 따라 셀 값을 얻는 방법은 무엇입니까?

Excel에서 일치하는 기준에 따라 셀 값을 얻는 방법은 무엇입니까?

그림과 같이 Excel 파일에 AC 열이 있습니다. 내 문제는 EG 열에 제공된 것과 같은 테이블을 만드는 것입니다. 엑셀에서는 어떻게 할 수 있나요?

여기에 이미지 설명을 입력하세요

답변1

아래 매크로는 첨부된 이미지에 표시된 모양으로 출력을 생성합니다.

'assumptions
'(1) the input data is in columns A,B,C
'(2) the output data is rendered in columns E,F,G
Sub ListByTeacher()
Dim noOfRows As Integer
Dim i As Integer
Dim j As Integer
Dim c_lv_array(1) As String ' c - course, lv - load value
Dim c As New Collection 'output table with values
Dim k As New Collection 'keys
Dim tmpVar As Variant

'[INPUT]
'identify no of rows with data
i = 1
Do While Len(Cells(i, 1).Value) > 0
    i = i + 1
Loop
noOfRows = i - 1

'Loop through input data rows and build the collection of teachers
For i = 2 To noOfRows
    c_lv_array(0) = Trim(CStr(Cells(i, 1).Value))
    c_lv_array(1) = Trim(CStr(Cells(i, 2).Value))
    On Error Resume Next
    tmpVar = c.Item(Trim(CStr(Cells(i, 3).Value))) 'if teacher in collection
    If IsArray(tmpVar) = True Then 'exists
        If InStr(1, tmpVar(0), c_lv_array(0), vbBinaryCompare) = 0 Then
            'c_lv_array(0) = c_lv_array(0) & ", " & tmpVar(0) 'use this line or below one
            c_lv_array(0) = tmpVar(0) & ", " & c_lv_array(0) 'reversed order to the above line
            c_lv_array(1) = CStr(CInt(c_lv_array(1)) + CInt(tmpVar(1)))
        End If
        c.Remove Trim(CStr(Cells(i, 3).Value))
        c.Add Item:=c_lv_array, Key:=Trim(CStr(Cells(i, 3).Value))
    End If
    tmpVar = Empty
    c.Add Item:=c_lv_array, Key:=Trim(CStr(Cells(i, 3).Value))
    k.Add Item:=Trim(CStr(Cells(i, 3).Value)), Key:=Trim(CStr(Cells(i, 3).Value))
Next i

'[OUTPUT]
'Render the result in s/s
Cells(1, 5) = "Teacher"
Cells(1, 6) = "Courses"
Cells(1, 7) = "Load"

j = 2
For i = 1 To c.Count
    tmpVar = c.Item(k.Item(i))
    Cells(j, 5) = k.Item(i)
    Cells(j, 6) = tmpVar(0)
    Cells(j, 7) = tmpVar(1)
    j = j + 1
Next i
End Sub

답변2

이를 위해서는 실제로 피벗 테이블을 만들어야 합니다.

이렇게 하면 EG의 다른 관측점을 지속적으로 업데이트하면서 AC 열의 목록에 추가할 수 있습니다.

하지만 두 가지가 필요합니다.

  1. 피벗 테이블의 값을 지속적으로 업데이트하려면 A~C 열을 테이블( CTRL + L)로 변환해야 합니다.
  2. 피벗 테이블에는 자체 시트가 있습니다.

관련 정보