엑셀 어느 부분이 잘못된 걸까요?ㅜ

꾸액2020.08.05
조회1,736
엑셀 작업 하는중인데 계속 424오류 뜨면서 저 부분에 노랑색 표시되고 잘못됐다고 계속 그러는데 도대체 뭐가 잘못된걸까요ㅜㅜㅜ

Sub SelectRandomSample()

Dim Population As Range

Dim lastRow As Long, firstrow As Long

Dim sampleSize As Long

Dim unique As Boolean

Dim i As Long, d As Long, n As Long

Sheets("Sheet2").Range("G:G").Clear

Sheets("Sheet2").Range("H:H").Clear

Set Population = Application.InputBox("추출할 샘플의 범위를 지정하세요.", Type:=8)

sampleSize = Application.InputBox("샘플의 갯수를 입력하세요.", Type:=1)

If Population.Count < sampleSize Then

MsgBox "샘플의 개수는 범위를 초과할 수 없습니다.", vbOKOnly + vbInformation

Exit Sub

End If

Set P = Population

lastRow = P.Rows.Count + P.Row - 1

firstrow = P.Row

 

n = Application.WorksheetFunction.RandBetween(firstrow, lastRow)

 

 

For i = 1 To sampleSize

Do

unique = True

n = Application.WorksheetFunction.RandBetween(firstrow, lastRow)

 

For d = 1 To i - 1

If Cells(d, 7) = n Then

unique = False

Exit For

End If

Next d

If unique = True Then

Exit Do

End If

 

Loop

Sheets("Sheet2").Select

Cells(i + 1, 4) = n

Cells(i + 1, 5) = Application.WorksheetFunction.Index(Population, n)

 

Next i

 

Sheets("Sheet2").Select

 

End Sub