我创建了一个UserForm来注册患者及其正常工作。
我尝试添加一个公式来连接F列中的第一个中间姓和第二个姓,但它给了我一个错误。我无法通过它。有什么建议吗?
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).Formula = "=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 & ")))"
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
我在这个明显的行中得到了运行时错误1004
.Cells(iRow, 6).Formula = "=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 & ")))"
该公式是西班牙文,相当于英文将
CONCATENAR = CONCATENATE
LIMPIAR = CLEAN
ESPACIOS = TRIM
SI = IF
答案 0 :(得分:0)
因为语言问题而改变了
.Cells(iRow, 6).Formula
到
.Cells(iRow, 6).FormulaLocal
像魅力一样工作