你能帮助我解决我的问题吗,我希望在我的程序中发生这样的事情,当你在userform中输入一个像textmp这样的文本框的名字时,它会以同样的方式传递给工作表
Private Sub cmdAdd_Click()
If cmdAdd.Caption = "ADD" Then
txtName.Enabled = True: cboAge.Enabled = True:
cmdAdd.Caption = "SAVE": cmdClose.Caption = "CANCEL"
txtName.SetFocus
Else
If txtName.Text = "" Or cboAge.Text = "" Then
MsgBox "Required field(s) missing!", vbCritical, "Message"
Else
For i = 2 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
If LCase(txtName.Text) = Sheet1.Cells(i, 1).Value And _
cboAge.Text = Sheet1.Cells(i, 2).Value Then
MsgBox "Record already exist!", vbExclamation, "Message"
Call UserForm_Activate
Exit Sub
End If
Next i
r = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheet1.Cells(r, 1).Value = (txtName.Text)
Sheet1.Cells(r, 2).Value = cboAge.Text
r = 0
MsgBox "One record saved!", vbInformation, "Message"
Call UserForm_Activate
End If
End If
End Sub
这是代码可以帮助我..谢谢你
答案 0 :(得分:1)
使用StrConv
转换为Propercase。请参阅此MSDN链接
Debug.Print StrConv(Textbox1.Text, vbProperCase)
例如(来自您的代码)
Sheet1.Cells(r, 1).Value = StrConv(txtName.Text, vbProperCase)