Private Sub backup() Dim tx As Control If Me.이름 = "" Then MsgBox "!" For Each tx In Me.Controls If TypeName(tx) = "TextBox" Then tx.Text = "": Me.그룹 = "": Next Me.번호 = Sheet3.Range("a7").CurrentRegion.Rows.Count
'### 컨트롤들을 순환하면서 textBox나 ComboBox에 값이 비어 있는게 있으면 blnBlank 변수를 True로 설정
'### blnBlank가 True이면 아무것도 안하고 기존 필드 모두 지움
'### blnBlank가 False이면(Not blnBlank이면) 입력된 내용을 시트에 추가함. 그리고 나서 모든 필드를 지움.
Private Sub CommandButton4_Click() Dim tx As Control
If Me.이름 = "" Then MsgBox "!" Exit Sub End If
Dim blnBlank As Boolean blnBlank = False For Each tx In Me.Controls If TypeName(tx) = "ComboBox" Or TypeName(tx) = "TextBox" Then If tx.Text = "" Then blnBlank = True End If Next
Dim rTarget As Range Set rTarget = Sheets("주소데이터").Range("A6") If Not blnBlank Then Set rTarget = rTarget.End(xlDown).Offset(1) With rTarget .Offset(0, 0) = Val(Me.번호) .Offset(0, 1) = Me.이름 .Offset(0, 2) = Me.그룹 .Offset(0, 3) = Me.회사명 .Offset(0, 4) = Me.직위 .Offset(0, 5) = Me.전화 .Offset(0, 6) = Me.휴대폰 .Offset(0, 7) = Me.이메일 .Offset(0, 8) = Me.주소 .Offset(0, 9) = Me.주소1 .Offset(0, 10) = Me.주소2 .Offset(0, 11) = Me.메모 End With End If
For Each tx In Me.Controls If TypeName(tx) = "ComboBox" Or TypeName(tx) = "TextBox" Then tx.Text = "" Next Me.번호 = rTarget.Value2 + 1
신강현님..
앞으로 주의하시겠다니 답변 드리겠습니다.
감사를 드린다거나의 문제가 아니라.. 하나씩 끝맺음을 해야 그 다음 단계로 넘어갈 수 있다는 말입니다.
답변이 적정했는지.. 해결이 되었는지.. 설명이 부족한지.. 확인이 되어야 그 다음 단계로 넘어갈 수 있습니다.
저도 제 답변이 잘 된 것인지 확인하고 싶구요.. 피드백이 있어야 답변 다는 맛도 나지 않겠습니까? ^-^;;
첨부파일을 참고하시기 바랍니다.
다운받기 : abyul.com_20130220_answer.xlsm
[ 기존 코드 ]
Private Sub backup()
Dim tx As Control
If Me.이름 = "" Then MsgBox "!"
For Each tx In Me.Controls
If TypeName(tx) = "TextBox" Then tx.Text = "": Me.그룹 = "":
Next
Me.번호 = Sheet3.Range("a7").CurrentRegion.Rows.Count
With Sheet3
.Cells(i, 1) = Val(Me.번호)
.Cells(i, 2) = Me.이름
.Cells(i, 3) = Me.그룹
.Cells(i, 4) = Me.회사명
.Cells(i, 5) = Me.직위
.Cells(i, 6) = Me.전화
.Cells(i, 7) = Me.휴대폰
.Cells(i, 8) = Me.이메일
.Cells(i, 9) = Me.주소
.Cells(i, 10) = Me.주소1
.Cells(i, 11) = Me.주소2
.Cells(i, 12) = Me.메모
End With
End Sub
[ 수정된 코드 ]
'### 일단 이름필드가 비어 있는지 검사.. 비어있으면 종료..
'### 컨트롤들을 순환하면서 textBox나 ComboBox에 값이 비어 있는게 있으면 blnBlank 변수를 True로 설정
'### blnBlank가 True이면 아무것도 안하고 기존 필드 모두 지움
'### blnBlank가 False이면(Not blnBlank이면) 입력된 내용을 시트에 추가함. 그리고 나서 모든 필드를 지움.
Private Sub CommandButton4_Click()
Dim tx As Control
If Me.이름 = "" Then
MsgBox "!"
Exit Sub
End If
Dim blnBlank As Boolean
blnBlank = False
For Each tx In Me.Controls
If TypeName(tx) = "ComboBox" Or TypeName(tx) = "TextBox" Then
If tx.Text = "" Then blnBlank = True
End If
Next
Dim rTarget As Range
Set rTarget = Sheets("주소데이터").Range("A6")
If Not blnBlank Then
Set rTarget = rTarget.End(xlDown).Offset(1)
With rTarget
.Offset(0, 0) = Val(Me.번호)
.Offset(0, 1) = Me.이름
.Offset(0, 2) = Me.그룹
.Offset(0, 3) = Me.회사명
.Offset(0, 4) = Me.직위
.Offset(0, 5) = Me.전화
.Offset(0, 6) = Me.휴대폰
.Offset(0, 7) = Me.이메일
.Offset(0, 8) = Me.주소
.Offset(0, 9) = Me.주소1
.Offset(0, 10) = Me.주소2
.Offset(0, 11) = Me.메모
End With
End If
For Each tx In Me.Controls
If TypeName(tx) = "ComboBox" Or TypeName(tx) = "TextBox" Then tx.Text = ""
Next
Me.번호 = rTarget.Value2 + 1
End Sub