避免额外的白色 Space VBA
Avoid Extra White Space VBA
我有一个将数据输入到另一个用户窗体的用户窗体,每次提交都会在新行中输入数据。我 运行 遇到了第一个输入的数据在我的用户表单上跳过一行的问题。我怎样才能调整我的代码以避免在开头有额外的白线,这是我的代码:
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
The red line shows the extra white space at the top of the text box
先测试一下是否为空。否则,您将 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
我有一个将数据输入到另一个用户窗体的用户窗体,每次提交都会在新行中输入数据。我 运行 遇到了第一个输入的数据在我的用户表单上跳过一行的问题。我怎样才能调整我的代码以避免在开头有额外的白线,这是我的代码:
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
The red line shows the extra white space at the top of the text box
先测试一下是否为空。否则,您将 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