我有一个用于患者注册的USerForm,在所述UserForm中存在用于选择主要医生的组合框,我希望根据医生选择生成患者ID,我甚至不开始从哪里开始,我希望代码能够评估哪个是最后一个具有相同前缀的ID以生成下一个ID,例如如何根据UserForm中的条件生成唯一ID
KT000001
KT000002
LG000001
下面是用户窗体代码
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Lista Pacientes")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a Valid patient name
If Trim(Me.TextBox1.Value) = "" Then
Me.TextBox1.SetFocus
MsgBox "Favor Introducir Nombre"
Exit Sub
End If
With ws
.Cells(iRow, 2).Value = Me.TextBox1.Value
.Cells(iRow, 3).Value = Me.TextBox2.Value
.Cells(iRow, 4).Value = Me.TextBox3.Value
.Cells(iRow, 5).Value = Me.TextBox4.Value
.Cells(iRow, 7).Value = Me.TextBox5.Value
.Cells(iRow, 8).Value = Me.TextBox6.Value
.Cells(iRow, 10).Value = Me.TextBox7.Value
.Cells(iRow, 11).Value = Me.TextBox8.Value
.Cells(iRow, 12).Value = Me.TextBox9.Value
.Cells(iRow, 13).Value = Me.TextBox10.Value
.Cells(iRow, 14).Value = Me.TextBox11.Value
.Cells(iRow, 15).Value = Me.TextBox12.Value
.Cells(iRow, 16).Value = Me.TextBox13.Value
.Cells(iRow, 17).Value = Me.ComboBox1.Value
.Cells(iRow, 6).FormulaLocal = "=CONCATENAR(LIMPIAR(ESPACIOS(B" & iRow & "));SI(LIMPIAR(ESPACIOS(C" & iRow & "))="""";"""";"" "");LIMPIAR(ESPACIOS(C" & iRow & "));SI(LIMPIAR(ESPACIOS(D" & iRow & "))="""";"""";"" "");LIMPIAR(ESPACIOS(D" & iRow & "));SI(LIMPIAR(ESPACIOS(E" & iRow & "))="""";"""";"" "");LIMPIAR(ESPACIOS(E" & iRow & ")))"
.Cells(iRow, 9).FormulaLocal = "=SIFECHA(H" & iRow & ";HOY();""Y"")"
End With
'clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
Me.TextBox8.Value = ""
Me.TextBox9.Value = ""
Me.TextBox10.Value = ""
Me.TextBox11.Value = ""
Me.TextBox12.Value = ""
Me.TextBox13.Value = ""
Me.ComboBox1.Value = ""
Me.TextBox1.SetFocus
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
是你问如何增加给定的ID('KT000001' - >'KT000002')或如何增加创建一个全新的(“患者数据” - >'KT000001')? – arcadeprecinct
我会在一个包含医生名单的单独工作表上做一个临时表格,并在第二个表格中填写“下一个患者ID”。在您将数据添加到数据库后,您将增加所选医生旁边的患者索引。你总是知道每位医生的下一个号码是什么。 – kamila
@arcadeprecinct创建一个完全新的 –