엑셀에서 같은 셀 안의 내용을
1. 맞춤법 순으로 정렬을 하고,
2. 중복된 값을 하나만 놔두고 지우기
한 셀 내의 문자를 구분자 구분하여 나눠서 중복제거를 한 다음 정렬한 코드입니다.
사용법은 셀 주소와 구분자를 표시하면 됩니다.
Function TxtSort(strR As Variant, strC As Variant) As Variant
'strR 은 정렬을 할 셀 선택
'strC 는 셀 구분자를 입력
Dim NC As New Collection
Dim strTxt As Variant
Dim temp As Variant
Dim cnt As Integer
Dim i As Integer
Dim j As Integer
cnt = (Len(strR) - Len(Application.WorksheetFunction.Substitute(strR, strC, ""))) / Len(strC)
ReDim strTxt(1 To cnt + 1)
For i = 1 To cnt
strTxt(i) = Left(strR, InStr(1, strR, strC) - 1)
strR = Mid(strR, Len(strTxt(i)) + Len(strC) + 1, Len(strR) - (Len(strTxt(i)) + Len(strC)))
Next i
strTxt(cnt + 1) = strR
On Error Resume Next
cnt = cnt + 1
For i = 1 To cnt
NC.Add strTxt(i), strTxt(i)
Next i
On Error GoTo 0
ReDim temp(NC.Count)
cnt = NC.Count
For i = 1 To cnt
For j = 1 To cnt
If NC(i) >= NC(j) Then
temp(i) = temp(i) + 1
End If
Next j
Next i
ReDim strTxt(NC.Count)
For i = 1 To cnt
strTxt(temp(i)) = NC(i)
Next
strR = strTxt(1)
For i = 2 To cnt
strR = strR & strC & strTxt(i)
Next
TxtSort = strR
End Function
'엑셀VBA' 카테고리의 다른 글
매크로 셀이동 (0) | 2011.06.14 |
---|---|
입력 받은 셀 주소로 이동하기 (0) | 2011.06.14 |
특정 일자와 가장 가까운 날짜값 찾기 (1) | 2011.02.12 |
범위에 중복값제외하고 모두표시 (1) | 2011.02.12 |
시트생성, 시트삭제, 강제저장 (0) | 2010.07.20 |