hope it helps you
Private Sub CommandButton1_Click()
'the question
If MsgBox("Do you want to add it?!", vbYesNo + vbQuestion, "Confirm?!") = vbYes Then
Dim NextCol1 As Long
Dim NextCol2 As Long
Dim NextCol3 As Long
'and so on
With ActiveSheet
NextCol1 = .Cells(2, .Columns.Count).End(xlToLeft).Column + 1
If TextBox1.Value <> "" Then
.Cells(2, NextCol1) = TextBox1.Value
Else
End If
NextCol2 = .Cells(3, .Columns.Count).End(xlToLeft).Column + 1
If TextBox2.Value <> "" Then
.Cells(3, NextCol2) = TextBox2.Value
Else
End If
NextCol3 = .Cells(5, .Columns.Count).End(xlToLeft).Column + 1
If TextBox3.Value <> "" Then
.Cells(5, NextCol3) = TextBox3.Value
Else
End If
'and so on
End With
End If
'clear the textboxes
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
'
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'the po box no format
If TypeName(Me.ActiveControl) = "TextBox" Then
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, ""The PO No box"" only numbers allowed!", vbCritical, "oops"
.Value = vbNullString
.SetFocus
End If
End With
End If
End Sub
Bookmarks