我在 Windows 7 上使用 Excel 2010。
我的用户表单包含一个时间戳,它正在工作,但是现在当我将数据保存在工作表中时,时间日期字段没有重新填充,它是一个设置为“现在”的文本字段。我收到不匹配错误。
Private Sub UserForm_Initialize()
TimeDate.Value = Now
TimeDate = Format(TimeDate.Value, "mmmm dd yyyy hh:mm")
City.List = Worksheets("Sheet2").Range("A2:A10").Value
State.List = Worksheets("Sheet2").Range("B2:B3").Value
Insurance.List = Worksheets("Sheet2").Range("C2:C7").Value
EBCAPServices.List = Worksheets("Sheet2").Range("D2:D3").Value
Patient.List = Worksheets("Sheet2").Range("D2:D3").Value
SelfEnroll.List = Worksheets("Sheet2").Range("D2:D3").Value
ContactType.List = Worksheets("Sheet2").Range("G2:G5").Value
Staff.List = Worksheets("Sheet2").Range("H2:H14").Value
End Sub
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub ClearButton_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
Private Sub OKbutton_Click()
Dim RowCount As Long
RowCount = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0).Value = DateValue(Me.TimeDate.Value)
.Offset(RowCount, 1).Value = Me.FirstName.Value
.Offset(RowCount, 2).Value = Me.LastName.Value
.Offset(RowCount, 3).Value = Me.Address1.Value
.Offset(RowCount, 4).Value = Me.Address2.Value
.Offset(RowCount, 5).Value = Me.City.Value
.Offset(RowCount, 6).Value = Me.State.Value
.Offset(RowCount, 7).Value = Me.ZipCode.Value
.Offset(RowCount, 8).Value = Me.Phone1.Value
.Offset(RowCount, 9).Value = Me.Phone2.Value
.Offset(RowCount, 10).Value = Me.Insurance.Value
.Offset(RowCount, 11).Value = Me.EBCAPServices.Value
.Offset(RowCount, 12).Value = Me.Patient.Value
.Offset(RowCount, 13).Value = Me.Income.Value
.Offset(RowCount, 14).Value = Me.FamilySize.Value
.Offset(RowCount, 15).Value = Me.SelfEnroll.Value
.Offset(RowCount, 16).Value = Me.SocialMedia.Value
.Offset(RowCount, 17).Value = Me.ContactType.Value
.Offset(RowCount, 18).Value = Me.Staff.Value
.Offset(RowCount, 19).Value = Me.Notes.Value
.Offset(RowCount, 0).Value = Format(Now, "mmmm dd yyyy hh:mm")
End With
If Staff.Value = "" Then
MsgBox "Please choose your initials."
Exit Sub
End If
If ContactType.Value = "" Then
MsgBox "Please choose the type of contact made."
Exit Sub
End If
If FirstName.Value = "" Then
MsgBox "Please enter a First Name."
FirstName.SetFocus
Exit Sub
End If
If LastName.Value = "" Then
MsgBox "Please enter a Last Name."
LastName.SetFocus
Exit Sub
End If
If Phone1.Value = "" Then
MsgBox "Please enter the phone number."
Phone1.SetFocus
Exit Sub
End If
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
Private Sub OnlyNumbers()
If TypeName(Me.ActiveControl) = "TextBox" Then
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
End If
End With
End If
End Sub
Private Sub FamilySize_Change()
OnlyNumbers
End Sub
Private Sub Income_Change()
OnlyNumbers
End Sub
Private Sub Phone1_Change()
OnlyNumbers
End Sub
Private Sub Phone2_Change()
OnlyNumbers
End Sub
Private Sub ZipCode_Change()
OnlyNumbers
End Sub