이 기사에서는 특정 조건을 대신하여 데이터를 그룹화하는 매크로를 만듭니다.

원시 데이터는 비즈니스 개발 팀 데이터로 구성됩니다. 이름, 전화 번호, 통화 별 매출로 구성됩니다.

ArrowRawData

이 기사에서는 에이전트 이름과 각 에이전트가 생성 한 총 수익을 기준으로 데이터를 그룹화하려고합니다.

ArrowOutput

논리 설명

필요한 계산을 수행하고 데이터를 그룹화하는 “DataGrouping”매크로를 만들었습니다. 고유 한 에이전트 이름과 각 에이전트가 생성 한 총 수익을 제공합니다.

코드 설명

LngLastRow = Cells (Rows.Count, 1) .End (xlUp) .Row 위 코드는 마지막 셀의 행 번호를 가져 오는 데 사용됩니다.

While Not Cells (i, 1) .Value = “”

Wend 위의 코드는 빈 셀이 나타날 때까지 반복하는 데 사용됩니다.

For LngRow = LngLastRow To (i + 1) Step -1 Next LngRow 위의 For 루프는 첫 번째 행을 지정하기 위해 마지막 행부터 시작하여 역 루핑에 사용됩니다.

Rng.Offset (0, 2) .Value = Rng.Offset (0, 2) .Value + Cells (LngRow, 3) .Value 위 코드는 지정된 기준에 따라 값을 합산하는 데 사용됩니다.

Rows (LngRow) .Delete 위 코드는 행을 삭제하는 데 사용됩니다.

아래 코드를 따르세요

Option Explicit

Sub DataGrouping()

'Declaring variables

Dim Rng As Range

Dim LngRow As Long, LngLastRow, i As Long

Application.ScreenUpdating = False

'Getting row number of last cell

LngLastRow = Cells(Rows.Count, 1).End(xlUp).Row

'Initializing the first row

i = 12

'Looping until blank cell is encountered in first column

While Not Cells(i, 1).Value = ""



'Initializing range object

Set Rng = Cells(i, 1)



'Looping from last row to specified first row

For LngRow = LngLastRow To (i + 1) Step -1



'Checking whether value in the cell is equal to specified cell

If Cells(LngRow, 1).Value = Rng.Value Then

Rng.Offset(0, 2).Value = Rng.Offset(0, 2).Value + Cells(LngRow, 3).Value

Rows(LngRow).Delete

End If

Next LngRow



i = i + 1



Wend

Application.ScreenUpdating = True

End Sub

이 블로그가 마음에 들면 Facebook 및 Facebook에서 친구들과 공유하십시오.

여러분의 의견을 듣고 싶습니다. 작업을 개선하고 더 나은 서비스를 제공 할 수있는 방법을 알려주십시오. [email protected]로 문의 해주세요