이 기사에서는 자동 필터에 사용되는 기준을 표시하는 매크로를 만듭니다.

원시 데이터는 이름, 전화 번호, 이메일 ID 및 회사 이름을 포함하는 클라이언트 세부 정보로 구성됩니다.

ArrowRawData

회사 열에 필터를 적용했으며 이제 필터가 적용되는 회사의 이름을 결정하려고합니다.

ArrowFilterData

“필터 데이터 분리”버튼을 클릭하여 필터가 적용되는 기준을 가져옵니다.

ArrowOutput

코드 설명

IntRow = Range ( “A10”). CurrentRegion.Rows.Count + 12 위 코드는 출력이 표시되어야하는 행 번호를 가져 오는 데 사용됩니다.

ActiveSheet.AutoFilter.Filters (IntCol) .On 위 코드는 특정 컬럼에 필터 적용 여부를 확인하는 데 사용됩니다.

Criteria1의 각 StringValue에 대해 MainString = MainString + Mid (StringValue, 2) + “|”

다음 위 코드는 필터에 사용되는 모든 기준 값으로 구성된 문자열을 만드는 데 사용됩니다.

Range ( “A10”). CurrentRegion.SpecialCells (xlCellTypeVisible) .Copy _ Cells (IntRow + 1, 1)

위의 코드는 보이는 행을 지정된 대상으로 복사하는 데 사용됩니다.

아래 코드를 따르세요

Option Explicit

Sub FilterCriteria()

'Declaring variables

Dim IntRow, IntCol As Integer

Dim MainString, StringValue As Variant

'Initializing the row and column number

IntRow = Range("A10").CurrentRegion.Rows.Count + 12

IntCol = 1

'Looping through all the cells until blank cell is encountered in the 10th row

Do Until IsEmpty(Cells(10, IntCol))



With ActiveSheet.AutoFilter.Filters(IntCol)

'Checking whether filter is applied on the column

If .On Then



MainString = "Filter On Column no. " & IntCol & " on values : "



'Creating text which consists of values used in the filter

For Each StringValue In .Criteria1

MainString = MainString + Mid(StringValue, 2) + "|"

Next



'Assigning value to cell

Cells(IntRow, 1).Value = MainString



Exit Do



End If



End With



IntCol = IntCol + 1

Loop

'Copying the visible cells to row after the filter data

Range("A10").CurrentRegion.SpecialCells(xlCellTypeVisible).Copy _

Cells(IntRow + 1, 1)

End Sub

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

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