Sub CreateRandomTest()
    Dim LastRow As Long
    Dim RandRow As Long
    Dim i As Integer
    Dim TestSize As Integer
    Dim Temp As String
    
    ' 시험 문제 수 설정
    TestSize = InputBox("몇 개의 단어로 시험을 볼까요?", "시험 문제 수 입력", 10)
    
    ' 데이터의 마지막 행을 찾습니다.
    LastRow = ThisWorkbook.Sheets("Sheet1").Cells(ThisWorkbook.Sheets("Sheet1").Rows.Count, "A").End(xlUp).Row
    
    ' 랜덤 단어 선택
    For i = 1 To TestSize
        RandRow = Int(Rnd * (LastRow - 1) + 1)
        ThisWorkbook.Sheets("Sheet2").Cells(i, 1).Value = ThisWorkbook.Sheets("Sheet1").Cells(RandRow, 1).Value
        ThisWorkbook.Sheets("Sheet2").Cells(i, 3).Value = ThisWorkbook.Sheets("Sheet1").Cells(RandRow, 2).Value
        ThisWorkbook.Sheets("Sheet2").Cells(i, 3).Font.Color = RGB(255, 255, 255) ' 흰색으로 글자 색상 변경
    Next i
    ' "문제 생성" 버튼 추가
    With ThisWorkbook.Sheets("Sheet2").Buttons.Add(200, 15, 100, 30) ' 버튼 위치 조정
        .OnAction = "CreateRandomTest"
        .Caption = "문제 생성"
    End With
    
    ' 채점하기 버튼 추가
    With ThisWorkbook.Sheets("Sheet2").Buttons.Add(400, 15, 100, 30) ' E열에 버튼 위치 조정
        .OnAction = "CheckAnswers"
        .Caption = "채점하기"
    End With
End Sub

Sub CheckAnswers()
    Dim i As Integer
    Dim LastRow As Long
    Dim UserAnswer As String
    Dim CorrectAnswer As String
    
    LastRow = ThisWorkbook.Sheets("Sheet2").Cells(ThisWorkbook.Sheets("Sheet2").Rows.Count, "A").End(xlUp).Row
    
    For i = 1 To LastRow
        UserAnswer = Trim(ThisWorkbook.Sheets("Sheet2").Cells(i, 2).Value) ' 공백 제거
        CorrectAnswer = ThisWorkbook.Sheets("Sheet2").Cells(i, 3).Value
        
        ' 답안의 글자 색상을 검은색으로 변경하여 보이게 함
        ThisWorkbook.Sheets("Sheet2").Cells(i, 3).Font.Color = RGB(0, 0, 0)
        
        ' 사용자의 답안이 빈칸이거나 없을 경우 "오답" 처리
        If UserAnswer = "" Then
            ThisWorkbook.Sheets("Sheet2").Cells(i, 4).Value = "오답"
        ElseIf InStr(1, CorrectAnswer, UserAnswer) > 0 Then
            ThisWorkbook.Sheets("Sheet2").Cells(i, 4).Value = "정답"
        Else
            ThisWorkbook.Sheets("Sheet2").Cells(i, 4).Value = "오답"
        End If
    Next i
End Sub

