'목록하단 광고 치환자(withSeok)
728x90

엑사남 25강 따라하기

유저폼 입력 오류검토.xlsm
0.03MB

Option Explicit

Private Sub CommandButton1_Click()

    Me.Tb_Name.BackColor = vbWhite
    Me.Cb_XY.BackColor = vbWhite
    Me.Tb_Age.BackColor = vbWhite

Dim strCheck As String
    strCheck = Data_Check

    If strCheck <> "" Then
        MsgBox strCheck, , "입력오류"
        Exit Sub
    End If

Dim intR As Integer
    intR = Cells(Rows.Count, "d").End(xlUp).Row + 1

    Range("c" & intR) = "=row()-2"
    Range("d" & intR) = Me.Tb_Name
    Range("e" & intR) = Me.Cb_XY
    Range("f" & intR) = Val(Me.Tb_Age)
        '숫자로 입력
    With Range("c" & intR).Resize(1, 4)
        .Borders.LineStyle = 1
        .HorizontalAlignment = xlCenter
    End With

    Range("d" & intR + 1).Select
Application.CutCopyMode = False

'Unload UserForm1

    Me.Tb_Name = ""
    Me.Cb_XY = ""
    Me.Tb_Age = ""

End Sub
Private Sub UserForm_Initialize()

    Me.Cb_XY.List = Array("남", "여")
End Sub
Private Function Data_Check() As String

Dim txtError As String
    txtError = ""

    If Me.Tb_Name = "" Then
        txtError = "성명 누락"
        Me.Tb_Name.BackColor = vbRed
    End If

    If Me.Cb_XY = "" Then
        txtError = txtError & vbCr & "성별 누락"
        Me.Cb_XY.BackColor = vbRed
    End If

    If Me.Tb_Age = "" Then
        txtError = txtError & vbCr & "나이 누락"
        Me.Tb_Age.BackColor = vbRed
    ElseIf Not IsNumeric(Me.Tb_Age) Then
        txtError = txtError & vbCr & "나이는 숫자만 입력"
        Me.Tb_Age.BackColor = vbRed
    End If

Data_Check = txtError

End Function
728x90

+ Recent posts