엑셀에서 같은 셀 안의 내용을
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
Posted by 조용문
BLOG main image
by 조용문

공지사항

카테고리

분류 전체보기 (66)
사진 (7)
흙건축 (14)
스틸하우스 (9)
D.I.Y (6)
프로그램 (0)
이동통신 (6)
농업 (1)
IoT (8)
엑셀VBA (13)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

태그목록

글 보관함

달력

«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Total :
Today : Yesterday :