2023. 12. 13. 12:01, 엑셀로 풀어가는 세상
반응형
엑셀 VBA #26 / For Each~Next_2 [VBA] - New Collection
On Error Resume Next
For Each c In rng
dc.Add Trim(c), CStr(Trim(c))
Next
On Error GoTo 0
For i = 1 To dc.Count
Cells(i + 11, "A") = dc(i)
Cells(i + 11, "B") = Application.SumIf(rc, dc(i), rs)
Sub For_Each_Next_and_New_Collection_고유값합계()
Dim dc As New Collection
Dim rng As Range
Dim c As Range
Dim i As Long
Dim rc As Range, rs As Range
Set rng = Range("A2:A" & Range("A2").CurrentRegion.Rows.Count)
'=Set rng = Range("A2", Cells(Rows.Count, "A").End(xlUp))
On Error Resume Next
For Each c In rng
dc.Add Trim(c), CStr(Trim(c))
Next
On Error GoTo 0
Range("A11") = "고유목록별 합계"
Set rc = Range("A2:A9")
Set rs = Range("B2:B9")
For i = 1 To dc.Count
Cells(i + 11, "A") = dc(i)
Cells(i + 11, "B") = Application.SumIf(rc, dc(i), rs)
Next
End Sub
핵심정리
On Error Resume Next
For Each c In rng
dc.Add Trim(c), CStr(Trim(c))
Next
On Error GoTo 0
https://www.youtube.com/watch?v=BC_O6sVx4SA&list=PLfxvqpVCYZ8e0qlyc_FU46neoWjO7yTWj&index=26
How to use VBA Collections in Excel
반응형
'엑셀로 풀어가는 세상' 카테고리의 다른 글
엑셀 VBA #30 / 정렬_1 [VBA] (0) | 2023.12.14 |
---|---|
엑셀 VBA #29 / VBA함수(split) [VBA] (0) | 2023.12.13 |
엑셀 VBA #28 / 워크시트 함수 [VBA] - Match이용 (0) | 2023.12.13 |
엑셀 VBA #27 / 배열 [VBA] - 배열 (0) | 2023.12.13 |
엑셀 VBA #25 / For Each~Next_1 [VBA] - 시트숨기기 (0) | 2023.12.13 |
엑셀 VBA #24 / For~Next_4 [VBA] - 시트 핸들링 (0) | 2023.12.13 |
엑셀 VBA #21 / For~Next_1 [VBA] 기본 (0) | 2023.12.13 |
엑셀 VBA #20 / Like 연산자_예제2 [VBA] (0) | 2023.12.13 |
Comments, Trackbacks