코딩 무엇인가요
Sub RepeatAndNumbering() Dim lastRow As Long Dim i As Long, j As Integer, currentRow As Long Dim repeatCount As Integer ' 반복 횟수 설정 repeatCount = 21 ' A열의 마지막 데이터 행 찾기 lastRow = Cells(Rows.Count, "A").End(xlUp).Row currentRow = 1 ' 결과값이 들어갈 시작 행 번호 ' 화면 깜빡임 방지 및 속도 향상 Application.ScreenUpdating = False ' A열의 1행부터 마지막 행까지 순회 For i = 1 To lastRow If Cells(i, "A").Value <> "" Then ' 빈 셀이 아닐 경우만 실행 For j = 1 To repeatCount ' B열에 1~21 넘버링 입력 Cells(currentRow, "B").Value = j ' C열에 A열 데이터 입력 Cells(currentRow, "C").Value = Cells(i, "A").Value currentRow = currentRow + 1 Next j End If Next i Application.ScreenUpdating = True MsgBox "작업이 완료되었습니다!"End Sub
광고 [X]를 누르면 내용과 AI가 해제됩니다
시스템 리소스 로딩 중...
0%
Sub RepeatAndNumbering() Dim lastRow As Long Dim i As Long, j As Integer, currentRow As Long Dim repeatCount As Integer ' 반복 횟수 설정 repeatCount = 21 ' A열의 마지막 데이터 행 찾기 lastRow = Cells(Rows.Count, "A").End(xlUp).Row currentRow = 1 ' 결과값이 들어갈 시작 행 번호 ' 화면 깜빡임 방지 및 속도 향상 Application.ScreenUpdating = False ' A열의 1행부터 마지막 행까지 순회 For i = 1 To lastRow If Cells(i, "A").Value <> "" Then ' 빈 셀이 아닐 경우만 실행 For j = 1 To repeatCount ' B열에 1~21 넘버링 입력 Cells(currentRow, "B").Value = j ' C열에 A열 데이터 입력 Cells(currentRow, "C").Value = Cells(i, "A").Value currentRow = currentRow + 1 Next j End If Next i Application.ScreenUpdating = True MsgBox "작업이 완료되었습니다!"End Sub
제시해주신 코드는 엑셀에서 사용하는 VBA(Visual Basic for Applications) 매크로입니다.
이 코드의 핵심 기능은 "A열에 있는 데이터를 각각 21번씩 반복하면서, 옆에 1부터 21까지 번호를 매겨주는 것"입니다. 주로 반복적인 라벨링이나 데이터 정규화 작업을 할 때 사용됩니다.
AI 분석 및 채팅
3/3
로딩이 완료되었습니다. 궁금한 점을 물어보세요!
답변 생성 중...