我有一个用户表单,可以将数据输入到另一个用户表单中,每次提交时都在新行中输入数据。我遇到了一个问题,其中第一个输入的数据跳过了用户表单上的一行。我该如何调整代码,以避免开头出现多余的白线,这是我的代码:
Private Sub CommandButton1_Click()
opsvision.opsfinding.Value = opsvision.opsfinding.Value & vbNewLine & "Employees" & "---" & generalbuilder.employees.Value & " -" & Space(2) & Space(1) & """" & Me.findings.Value & """" & Space(5) & "----" & Space(3) & "Finding Conducted by: " & Worksheets("userform").Range("B3") & vbNewLine
Unload Me
End Sub
答案 0 :(得分:2)
先测试一下是否为空。否则,您将vbNewLine
连接到空的起始值:
Private Sub CommandButton1_Click()
Dim line As String
line = "Employees" & "---" & generalbuilder.employees.Value & " -" & Space(2) & _
Space(1) & """" & Me.findings.Value & """" & Space(5) & "----" & Space(3) & _
"Finding Conducted by: " & Worksheets("userform").Range("B3") & vbNewLine
If opsvision.opsfinding.Value = vbNullString Then
opsvision.opsfinding.Value = line
Else
opsvision.opsfinding.Value = opsvision.opsfinding.Value & vbNewLine & line
End If
Unload Me
End Sub