
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
아예 비어있는 파일에서는 되는데
데이터가 입력된 파일에서는 실행이 안됩니다.

작성한 코드 및 에러 메세지
Sub ExtractGames()
Dim sourceSheet As Worksheet
Dim destinationSheet As Worksheet
Dim lastRow As Long
Dim currentRow As Long
Dim audienceCount As Long
Dim meanAudienceCount As Long
Dim dateValue As String
Dim vsValue As String
' 데이터 추출할 소스 시트 설정
Set sourceSheet = ThisWorkbook.Sheets("sheet1")
' 결과 저장할 대상 시트 설정
Set destinationSheet = ThisWorkbook.Sheets.Add(After:=sourceSheet)
destinationSheet.Name = "추출된_데이터_시트2"
' 결과 시트에 헤더 추가
destinationSheet.Range("A1:F1").Value = Array("Date", "VS", "Score", "Win/Lose", "Audience Count", "Mean Audience Count")
' 소스 시트의 마지막 행 찾기
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, 1).End(xlUp).Row
' 데이터 추출 및 결과 시트에 저장
currentRow = 2 ' 결과 시트의 시작 행
For i = 2 To lastRow ' 소스 시트에서 데이터를 추출할 시작 행 (헤더를 제외한 첫 번째 행)
audienceCount = sourceSheet.Cells(i, 5).Value
meanAudienceCount = sourceSheet.Cells(i, 6).Value
' audienceCount가 meanAudienceCount보다 큰 경우 데이터 추출
If audienceCount > meanAudienceCount Then
dateValue = sourceSheet.Cells(i, 1).Value
vsValue = sourceSheet.Cells(i, 2).Value
destinationSheet.Cells(currentRow, 1).Value = dateValue
destinationSheet.Cells(currentRow, 2).Value = vsValue
' 다른 필요한 데이터도 추출하여 결과 시트에 저장
currentRow = currentRow + 1 ' 다음 행으로 이동
End If
Next i
End Sub
