728x90
엑사남 25강 따라하기 |
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
'■ Excel > ㅡExcel VBA Study' 카테고리의 다른 글
엑셀 vba 유효성 검사와 유저폼 (0) | 2020.06.29 |
---|---|
엑셀 VBA창에서 주석 처리 간단하게(엑사남님의 강의) (0) | 2020.06.26 |
엑셀 vba 유저폼 텍스트박스 가운데 정렬 미묘한 조정 (0) | 2020.06.24 |
엑셀 vba 유저폼 UserForm 사용하기 (0) | 2020.06.23 |
엑셀 vba 범위, 합집합, 교집합, 콤마(쉼표) (0) | 2020.06.23 |